Module Moonpool.Chan

Channels.

The channels have bounded size. Push/pop return futures or can use effects to provide an await-friendly version.

The channels became bounded since @0.7 .

type 'a t

Channel carrying values of type 'a.

val create : max_size:int -> unit -> 'a t

Create a channel.

exception Closed
val try_push : 'a t -> 'a -> bool

try_push chan x pushes x into chan. This does not block. Returns true if it succeeded in pushing.

  • raises Closed

    if the channel is closed.

val try_pop : 'a t -> 'a option

try_pop chan pops and return an element if one is available immediately. Otherwise it returns None.

  • raises Closed

    if the channel is closed and empty.

val close : _ t -> unit

Close the channel. Further push and pop calls will fail. This is idempotent.

val push : 'a t -> 'a -> unit

Push the value into the channel, suspending the current task if the channel is currently full.

  • raises Closed

    if the channel is closed

  • since 0.7
val pop : 'a t -> 'a

Pop an element. This might suspend the current task if the channel is currently empty.

  • raises Closed

    if the channel is empty and closed.

  • since 0.7