Skip to content

Instantly share code, notes, and snippets.

@lefticus
Created January 7, 2015 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lefticus/ac4d8671ca9bb839ec03 to your computer and use it in GitHub Desktop.
Save lefticus/ac4d8671ca9bb839ec03 to your computer and use it in GitHub Desktop.
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