Skip to content
This repository
Browse code

winner ~~ s/nobody/wait 0/

  • Loading branch information...
commit c5b7d733fb999738044a5039acfac9f44277d3b7 1 parent dabb21e
Larry Wall TimToady authored

Showing 1 changed file with 14 additions and 10 deletions. Show diff stats Hide diff stats

  1. +14 10 S17-concurrency.pod
24 S17-concurrency.pod
Source Rendered
@@ -13,8 +13,8 @@ RE-DRAFT: Synopsis 17: Concurrency
13 13
14 14 Created: 3 Nov 2013
15 15
16   - Last Modified: 18 Nov 2013
17   - Version: 8
  16 + Last Modified: 19 Nov 2013
  17 + Version: 9
18 18
19 19 This synopsis is based around the concurrency primitives and tools currently
20 20 being implemented in Rakudo on the JVM. It covers both things that are
@@ -380,15 +380,19 @@ be thrown. There is also a C<winner> statement [keywords still negotiable]:
380 380 done $p2 { say "Second promise got a value" }
381 381 }
382 382
383   -That will invoke the closure associated with the first promise that produces a
384   -result, either kept or broken. In order to avoid blocking, it is possible to
385   -provide a closure with the C<nobody> keyword, that will be invoked if none of
386   -the promises currently have a result available.
  383 +That will invoke the closure associated with the first promise that
  384 +produces a result, either kept or broken.
387 385
388   - winner * {
389   - done $p1 { say "First promise got a value" }
390   - done $p2 { say "Second promise got a value" }
391   - nobody { say "Not done yet" }
  386 +It's possible to add a timer using the keyword C<wait> followed
  387 +by the number of seconds to wait (which may be fractional). As a
  388 +degenerate case, in order to avoid blocking at all you may use a
  389 +C<wait 0>. The timeout is always checked last, to guarantee that
  390 +the other entries are all tried at least once before timing out.
  391 +
  392 + my $gotone = winner * {
  393 + done $p1 { say "First promise got a value"; $p1 }
  394 + done $p2 { say "Second promise got a value"; $p2 }
  395 + wait 0 { say "Not done yet"; Nil }
392 396 }
393 397
394 398 The construct as a whole returns the result of whichever block was selected.

0 comments on commit c5b7d73

Please sign in to comment.
Something went wrong with that request. Please try again.