Skip to content

Instantly share code, notes, and snippets.

@adam-singer
Created March 14, 2012 06:00
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 adam-singer/2034422 to your computer and use it in GitHub Desktop.
Save adam-singer/2034422 to your computer and use it in GitHub Desktop.
Isolate Wait Then in Dart. Sometimes called Fork/Join
#import('dart:isolate', prefix:'isolate');
costlyQuery() {
isolate.port.receive((msg, reply) => reply.send("costly"));
}
expensiveWork() {
isolate.port.receive((msg, reply) => reply.send("expensive"));
}
lengthyComputation() {
isolate.port.receive((msg, reply) => reply.send("lengthy"));
}
void main() {
Futures.wait([
isolate.spawnFunction(costlyQuery).call(""),
isolate.spawnFunction(expensiveWork).call(""),
isolate.spawnFunction(lengthyComputation).call(""),
]).then((values) => print(values));
// prints [costly, expensive, length]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment