Created
October 2, 2014 13:05
-
-
Save back2dos/946e6b43d8f46649b5d0 to your computer and use it in GitHub Desktop.
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
| var run = true; | |
| Thread.create(function () { | |
| Sys.getChar(true); | |
| run = false; | |
| }); | |
| while (run) { | |
| Sys.sleep(.5); | |
| println('yay');//assume this would block until the other side reads in fact | |
| } | |
| //becomes: | |
| var done = false; | |
| function loop() | |
| return | |
| if (done) Halt(null); | |
| else | |
| Held(Future.async(function (cb) | |
| haxe.Timer.delay(function () cb(Emit(Right('yay'), loop())), 500); | |
| )); | |
| Emit( | |
| Left(function (_) { | |
| var wasFirst = done == false; | |
| done = true; | |
| return wasFirst; | |
| }), | |
| loop() | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment