Created
August 1, 2014 17:48
-
-
Save leafo/af586833cd6adaab4c04 to your computer and use it in GitHub Desktop.
This file contains 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
import sleep from require "socket" | |
async_function = (fn) -> | |
fn! | |
-- async_function -> | |
-- print "first" | |
-- async_function -> | |
-- print "second" | |
-- async_function -> | |
-- print "third" | |
-- | |
-- --- | |
make_procedural = (fn) -> | |
-> | |
thread = coroutine.running! | |
fn (...) -> | |
coroutine.resume thread, ... | |
coroutine.yield thread | |
sync_func = make_procedural async_function | |
thread = coroutine.create -> | |
sync_func! | |
print "first" | |
sync_func! | |
print "second" | |
sync_func! | |
print "third" | |
coroutine.resume thread |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment