futures: Allow nested futures; put the main thread to work.
authorLudovic Courtès <ludo@gnu.org>
Fri, 16 Nov 2012 23:20:21 +0000 (00:20 +0100)
committerLudovic Courtès <ludo@gnu.org>
Wed, 21 Nov 2012 22:33:30 +0000 (23:33 +0100)
commit3e529bf02af7939c7c7d06ed68f0108b336ed4d2
tree104a8303771f0d1eb04fe50dc26bbd4ff603cb5a
parentab975cf592a89eee30fec94e77ef064eda0b38b5
futures: Allow nested futures; put the main thread to work.

* module/ice-9/futures.scm (%futures-waiting, %within-future?,
  %future-prompt): New variables.
  (let/ec): New macro.
  (process-future!): Run FUTURE's thunk in a prompt; capture FUTURE's
  continuation when it aborts, and add it to %FUTURES-WAITING.  Set
  %WITHIN-FUTURE? in the dynamic extent of the call FUTURE's thunk.
  (process-futures): Move loop body to...
  (process-one-future): ... here.  New procedure.
  (notify-completion): New procedure.
  (touch)[work, loop]: New procedures.
  When %WITHIN-FUTURE? and FUTURE is started, abort; if not
  %WITHIN-FUTURE, call `work' while waiting.
  When FUTURE is queued, call `work' too.

* test-suite/tests/future.test ("nested futures"): New tests.
module/ice-9/futures.scm
test-suite/tests/future.test