generate
generates a sequence asynchronously
Usage:
(generate form+)
Evaluate the specified forms in a separate thread of execution. Returns a sequence that will iterate over any of the values that are emitted. Values are emitted using a locally scoped function of the form (emit value)
. The forms are executed as a co-routine, meaning that a call to emit will block until the corresponding element is resolved by a consumer of the sequence.
An Example
(define colors (generate
(emit "red")
(emit "orange")
(emit "yellow")))
(seq->vector colors)
This example will bind the lazy sequence returned by the call to generate to the name colors
. The seq->vector call will block until that variable is fully consumed, and then return the vector [“red” “orange” “yellow”].