Skip to content

Instantly share code, notes, and snippets.

@back2dos
Created October 2, 2014 13:05
Show Gist options
  • Select an option

  • Save back2dos/946e6b43d8f46649b5d0 to your computer and use it in GitHub Desktop.

Select an option

Save back2dos/946e6b43d8f46649b5d0 to your computer and use it in GitHub Desktop.
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