gather
takes a channel as argument and returns a
promise. All values emitted by the channel will be collected
into a vector matching the prototype mode. After the source
channel closes, the promise will resolve with the collected
vector.
Method as.promise.channel
is a synonym for gather
.
collect
and collector
are used in the
implementation of the above functions. collect
calls the
function fn
in its argument, supplying a callback of the form
function (val, name=NULL).
I like to call it emit
. While
fn
is running, it can call emit(x)
any number of times.
After fn
returns, all the values passed to emit
are returned
in a vector, with optional names.
collector()
works similarly to collect() but does
not gather values when your inner function returns. Instead, it
provides your inner function with two callbacks, one to add a
value and the second to extract the value; so you can use that
callback to extract values at a later time. For an example of
collector
usage see the definition of gather.