David K. Storrs
Wraps an arbitrary value into a synchronizable event.
Syncing something that is already an event works as usual.
Syncing on a procedure returns the procedure’s result unless you disable this behavior via the #:eval-proc? keyword. (If evaluated, the procedure is called with no arguments.)
Syncing on a list recursively syncs the elements of the list unless you disable this behavior via the #:recurse-lists? keyword.
In all other cases, the synchronization result is the original value.
;value-evts are both evt? and value-evt?. They sync to their argument> e#<value-evt>
#t
#t
9
;;By default, syncing on a procedure syncs to the return value4
;You can instead get the procedure itself back#<procedure:proc>
;It's not a problem to specify #:eval-proc? on something that isn't a procedure"eval-proc? keyword is ignored for non-proc"
;;eventify always returns an evt;Things that are evts are unchanged#t
#t
;Things that are not evts become value-evts#f
#t
;;by default, value-evts containing a list sync recursively'(arg1-ch-okarg2-ch-ok)
;;You can ask for it to return the original list'(#<channel>#<channel>)
;;all-evt is the same as value-evt but takes a rest argument;so you don't have to supply your own listall-evt returns: #<value-evt>
'(arg1-ch-okarg2-ch-ok)
procedure
[ #:eval-proc?eval-proc?v:any/c
If the value is a procedure and eval-proc? is #t (the default) then the procedure will be called with no arguments and the synchronization result of the value-evt will be the return value of the procedure.
If the value is a list and recurse-lists? is #t (the default) then each element of the list will have (compose1 sync eventify ) called on it and the synchronization event of the original event will be a list containing the synchronization results of each of the list items. This process is recursive.
This provides a convenient way to run an arbitrary function and wait for it to complete without having to do polling, apply strictures to your interface (if the function is being passed in), or otherwise contort the code. If you want to actually return the lambda then you may use #:eval-proc?#f. Similarly, #:recurse-lists? makes it easy to handle the case where you want to wait for multiple events to complete before proceeding. A typical example would be waiting for a network connection to a server and simultaneously waiting for configuration files to be read and setup to be performed.
procedure
( value-evt? v)→boolean?
v:any/c
v:any/c
procedure
#:recurse-lists?recurse-lists?]arg:any/c