concurrency: fix lazy evaluation
The 'lazy' word wasn't allowing multiple requests for the lazy value. It now caches the lazy value once it's computed and immediately returns it.
parent
cda21fa9a6
commit
f1e9dc12e6
|
@ -423,22 +423,16 @@ C: promise ( -- <promise> )
|
|||
! ******************************
|
||||
! Experimental code below
|
||||
! ******************************
|
||||
SYMBOL: lazy-quot
|
||||
: (lazy) ( v -- )
|
||||
receive over reply (lazy) ;
|
||||
|
||||
: lazy ( quot -- lazy )
|
||||
#! Spawn a process that immediately blocks and return it.
|
||||
#! When '?lazy' is called on the returned process, call the quotation
|
||||
#! and return the result. The quotation must have stack effect ( -- X ).
|
||||
[
|
||||
[
|
||||
lazy-quot set
|
||||
[
|
||||
[ tagged-message? [ [ drop t ] [ get call ] send-reply ] ]
|
||||
] recv
|
||||
] with-scope
|
||||
] curry spawn ;
|
||||
[ receive >r call r> over reply (lazy) ] spawn nip ;
|
||||
|
||||
: ?lazy ( lazy -- result )
|
||||
#! Given a process spawned using 'lazy', evaluate it and return the result.
|
||||
lazy-quot swap send-synchronous ;
|
||||
f swap send-synchronous ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue