Misty Programming Language:

Parseq Functions

The parseq module provides tools for working with callbacks and eventual programming. The name combines the prefixes of parallel and sequence.

The parseq module requires that the process has the @.delay capability.

use parseq

Function types

The parseq module works with functions of these types: callbacks, requestors, cancels, and factories.


Callbacks are a functional pattern used to deliver results from the future. A callback function has a signature of

ƒ callback(value, reason)

Instead of returning a value, a function may be written to use a provided callback function, passing the value as an argument.

return callback(value)

If the value is null, that indicates failure. The optional argument reason can be used to provide documentation about the failure.

return callback(null, "My dog ate my return value.")






The requestor function makes and returns a requestor function. A requestor function has a signature of

ƒ requestor(callback, value)

The requestor will eventually call the callback function, giving its value.

A callback frunction has a signature of

ƒ callback(value, reason)

If the requestor was successful, it will pass its result as the callback's value. If the requestor is not successful, it will pass null as the callback's value, and optionally a reason for the failure.

The requestor function takes a record argument that specifies the record to be made. The record contains these fields:


fallback(array, time_limit)

parallel(requireds, optionals, time_limit, throttle)

The parallel takes a set of requestor functions and returns a requestor function that starts them all at once. It ultimately produces an array of all of the results.

The requireds and optionals are an array or record of requestor functions. Either can be null, but not both. Otherwise, requireds and optionals must be the same type. The required requestors must all succeed if the parallel requestor is to succeed. An optional requestor can be unsuccessful without affecting the success of the whole.

A time_limit (in seconds) can be imposed.

A throttle may be used to limit the number of requestors that are running concurrently. This can be used to reduce stress on fragile systems.

race(array, time_limit, throttle)

sequence(array, time_limit)