Dex.Channel

g Dex.Channel Dex.Channel Dex.Object Dex.Object Dex.Object->Dex.Channel

Subclasses:

None

Methods

Inherited:

Dex.Object (2)

class

new (capacity)

can_receive ()

can_send ()

close_receive ()

close_send ()

receive ()

receive_all ()

send (future)

Virtual Methods

None

Fields

None

Class Details

class Dex.Channel
Bases:

Dex.Object

Abstract:

No

classmethod new(capacity)
Parameters:

capacity (int) – the channel queue depth or 0 for unlimited

Returns:

a new Dex.Channel

Return type:

Dex.Channel

Creates a new Dex.Channel.

If capacity is non-zero, it can be used to limit the size of the channel so that functions can asynchronously stall until items have been removed from the channel. This is useful in buffering situations so that the producer does not outpace the consumer.

can_receive()
Return type:

bool

can_send()
Return type:

bool

close_receive()
close_send()
receive()
Returns:

a Dex.Future

Return type:

Dex.Future

Receives the next item from the channel.

The resulting future will resolve or reject when an item is available to the channel or when send side has closed (in that order).

receive_all()
Returns:

a Dex.Future

Return type:

Dex.Future

Will attempt to receive all items in the channel as a #DexResultSet.

If the receive side of the channel is closed, then the future will reject with an error.

If there are items in the queue, then they will be returned as part of a #DexResultSet containing each of the futures.

Otherwise, a Dex.FutureSet will be returned which will resolve or reject when the next item is available in the channel (or the send or receive sides are closed).

send(future)
Parameters:

future (Dex.Future) – a Dex.Future

Returns:

a Dex.Future

Return type:

Dex.Future

Queues future into the channel.

The other end of the channel can receive the future (or a future that will eventually resolve to future) using Dex.Channel.receive().

This function returns a Dex.Future that will resolve when the channels capacity is low enough to queue more items.

If the send side of the channel is closed, the returned Dex.Future will be rejected with Dex.Error.CHANNEL_CLOSED.