Flow

Abstract

Easy cooperative, concurrent, and parallel computation.

TODO

Reference

(flow-time) → positive-integer? positive-integer?

Rationale: it can help to benchmark at runtime the execution of flows, and scale accordingly the number of flows.

Returns two numbers, the first represents seconds, the second nanoseconds. The whole represent an absolute time.

Note: it might just be a shortcut for jiffies.

(flow-spawn [priority] thunk) positive-integer? procedure?

Starts a new flow of execution with THUNK. If THUNK raise an object the behavior is unspecified. When THUNK returns, returned values, if any, are unreachable.

PRIORITY is a hint to help the host choose what flow to execute. The default value of PRIORITY is zero. A priority of +inf.0 instruct that THUNK should have exclusive / dedicated access to one computation unit.

(make-flow-channel)

Returns a channel.

(flow-channel? obj)

Returns true, if OBJ is a channel, otherwise false. A channel allows communication between flows.

(flow-operation? obj)

Returns true, if OBJ is an operation, otherwise false.

(flow-wrap operation proc)

Wrap an operation with PROC. When OPERATION is applied by flow-apply returned values called objs, will be applied to PROC before flow-apply returns.

(flow-produce channel objs ...)

Returns an operation, that will produce OBJS in CHANNEL when applied by flow-apply, and will return no values.

A flow that is producing values on a channel, may wait indefinitly if there is nobody consuming on the same channel.

flow-produce will apply once and only once with one and only one flow-consume.

(flow-consume channel)

Returns an operation, that will consume and return objects produced on CHANNEL when applied by flow-apply.

A flow may wait indefinitly if there is nobody producing on the same channel.

flow-consume will apply once and only once with one and only one flow-produce.

(flow-sleep seconds [nanoseconds])

Returns an operation. When applied by flow-apply returns after SECONDS and NANOSECONDS In other words the following code will return after one second, the value 'done-sleeping:

(flow-apply (flow-wrap (flow-sleep 1) (lambda () 'done-sleeping)))

It can be used with flow-choice to implement timeouts, and avoid the situations where flows wait indefinitly.

(flow-choice operations)

Returns an operation made of all OPERATIONS. When applied, it will return the return values, of one and only one operation.

(flow-apply operation)

Apply an operation. The flow that called flow-apply does not necessarly return immediatly.

Examples

Implementation

??? explanation of how it meets the sample implementation requirement (see process), and the code, if possible, or a link to it Source for the sample implementation.

Acknowledgements

??? Give credits where credits is due.

References

Many.