Top Level Namespace

Defined Under Namespace

Modules: Enumerable, Sink Classes: Array, Consumer, CoroutineError, Hash, IO, Method, Object, Proc, String, Symbol, Transformer

Constant Summary collapse

Multicast =

convenience alias for Sink::Multicast (this is not defined when requiring just coroutines/base)

Sink::Multicast

Instance Method Summary collapse

Instance Method Details

#awaitObject

:call-seq:

await -> obj

Evaluates to the next input value from the associated consumption context. In order to create a consumption context, you have to use Object#consum_for or Object#trans_for on the method calling await.

The behavior of await is undefined if the method using it is called without being wrapped by consum_for or trans_for. It should be an error to do so, as it is an error to use yield without an associated block; however, since await is not a language primitive (like yield), it is not always possible to enforce this. This is likely to change in a future version if a better solution can be found.

Raises:



121
122
123
124
125
# File 'lib/coroutines.rb', line 121

def await
  yielder = Fiber.current.instance_variable_get(:@yielder)
  raise CoroutineError, "you can't call a consumer" if yielder.nil?
  yielder.await
end