Created
January 7, 2015 16:15
-
-
Save lefticus/ac4d8671ca9bb839ec03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var func = fun(){ | |
var ret = 0; | |
for (var i = 0; i < 1000000; ++i) { | |
ret += i; | |
} | |
return ret; | |
} | |
// async takes a 0 parameter function object which is run asynchronously and | |
// returns a Boxed_Value (ie, any value, including void, should work) | |
var fut1 := async(func); | |
var fut2 := async(func); | |
var fut3 := async(func); | |
var fut4 := async(func); | |
// now join all of the futures and get their values out. If one caused an exception, the exception | |
// would be re-thrown now (and catchable inside of ChaiScript) retaining the same semantics | |
// as std::future. | |
print(" ${fut1.get()} ${fut2.get()} ${fut3.get()} ${fut4.get()}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment