Next: , Previous: , Up: Fibers   [Contents][Index]


4.14.2 Operations

Operations are first-class abstractions for asynchronous events. There are primitive operation types, such as waiting for a timer (see Timers) or waiting for a message on a channel (see Channels). Operations can also be combined and transformed using the choice-operation and wrap-operation from the (fibers operations) module.

Procedure: wrap-operation op f

Given the operation op, return a new operation that, if and when it succeeds, will apply f to the values yielded by performing op, and yield the result as the values of the wrapped operation.

Procedure: choice-operation . ops

Given the operations ops, return a new operation that if it succeeds, will succeed with one and only one of the sub-operations ops.

Finally, once you have an operation, you can perform it using perform-operation.

Procedure: perform-operation op

Perform the operation op and return the resulting values. If the operation cannot complete directly, block until it can complete.

There is also a low-level constructor for other modules that implement primitive operation types:

Procedure: make-base-operation wrap-fn try-fn block-fn

Make a fresh base operation.