Created
October 10, 2011 09:58
-
-
Save DmitrySoshnikov/1274980 to your computer and use it in GitHub Desktop.
Dart's isolate test
This file contains hidden or 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
class Printer extends Isolate { | |
main() { | |
port.receive((message, replyTo) { | |
if (message == null) port.close(); | |
else print(message); | |
}); | |
} | |
} | |
main() { | |
// first isolate process | |
new Printer().spawn().then((port) { | |
for (var message in ['Hello', 'from', 'other', 'isolate']) { | |
port.send(message); | |
} | |
port.send(null); | |
}); | |
// second isolate process | |
new Printer().spawn().then((port) { | |
for (var message in ['*Hello', '*from', '*other', '*isolate']) { | |
port.send(message); | |
} | |
port.send(null); | |
}); | |
} | |
// Results (WTF?) | |
Hello | |
from | |
other | |
isolate | |
*Hello | |
*from | |
*other | |
*isolate | |
// Why the output is sequential but not parallel? How the Dart's processes' scheduler work? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@DmitrySoshnikov: as far as I know, most ES engines do not support
yield
, except *Monkey. Therefore, I also believe the Dart engineers decided it is not possible to support "parallel processes" in transcompiled JS and this is the outcome :(. By the way, I like https://gist.github.com/1127536, did something similar once as well :)