Arrggh
parent
3a22b3aaa0
commit
e9a63d7a2c
|
@ -264,26 +264,36 @@ PRIVATE>
|
||||||
#! so the server continuation gets its new self updated.
|
#! so the server continuation gets its new self updated.
|
||||||
self swap call ;
|
self swap call ;
|
||||||
|
|
||||||
TUPLE: future status value processes ;
|
TUPLE: future value processes ;
|
||||||
|
|
||||||
|
: notify-future ( value future -- )
|
||||||
|
tuck set-future-value
|
||||||
|
dup future-processes [ schedule-thread ] each
|
||||||
|
f swap set-future-processes ;
|
||||||
|
|
||||||
: future ( quot -- future )
|
: future ( quot -- future )
|
||||||
#! Spawn a process to call the quotation and immediately return
|
#! Spawn a process to call the quotation and immediately return.
|
||||||
#! a 'future' on the stack. The future can later be queried with
|
\ future construct-empty [
|
||||||
#! ?future. If the quotation has completed the result will be returned.
|
|
||||||
#! If not, the process will block until the quotation completes.
|
|
||||||
#! 'quot' must have stack effect ( -- X ).
|
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
|
>r [ t 2array ] compose [ f 2array ] recover r>
|
||||||
|
notify-future
|
||||||
|
] 2curry spawn drop
|
||||||
|
] keep ;
|
||||||
t
|
t
|
||||||
] compose
|
] compose
|
||||||
] spawn drop
|
] spawn drop
|
||||||
[ self send ] compose spawn ;
|
[ self send ] compose spawn ;
|
||||||
|
|
||||||
: ?future ( future -- result )
|
: ?future ( future -- result )
|
||||||
#! Block the process until the future has completed and then
|
#! Block the process until the future has completed and then
|
||||||
#! place the result on the stack. Return the result
|
#! place the result on the stack. Return the result
|
||||||
#! immediately if the future has completed.
|
#! immediately if the future has completed.
|
||||||
process-mailbox mailbox-get ;
|
dup future-value [
|
||||||
|
first2 [ throw ] unless
|
||||||
|
] [
|
||||||
|
dup [ future-processes push stop ] curry callcc0 ?future
|
||||||
|
] ?if ;
|
||||||
|
|
||||||
: parallel-map ( seq quot -- newseq )
|
: parallel-map ( seq quot -- newseq )
|
||||||
#! Spawn a process to apply quot to each element of seq,
|
#! Spawn a process to apply quot to each element of seq,
|
||||||
|
|
Loading…
Reference in New Issue