Skip to content

Instantly share code, notes, and snippets.

@leafo
Created August 1, 2014 17:48
Show Gist options
  • Save leafo/af586833cd6adaab4c04 to your computer and use it in GitHub Desktop.
Save leafo/af586833cd6adaab4c04 to your computer and use it in GitHub Desktop.
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