Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A cheating 'await', to get the API in place.
  • Loading branch information
jnthn committed Jul 12, 2013
1 parent 6f93cae commit 125f458
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/vm/jvm/core/Threading.pm
Expand Up @@ -193,3 +193,15 @@ $PROCESS::SCHEDULER = ThreadPoolScheduler.new();
sub async(&code) {
Promise.new(:scheduler($*SCHEDULER), :&code);
}

# Waits for a promise to be delivered and, once it is, unwraps the result.
# This should be made more efficient by using continuations to suspend any
# task running in the thread pool that awaits; for now, this cheat gets the
# basic idea in place.
proto sub await(|) { * }
multi sub await(Promise $p) {
$p.result
}
multi sub await(*@promises) {
@promises.eager.map(&await)
}

0 comments on commit 125f458

Please sign in to comment.