Skip to content

Instantly share code, notes, and snippets.

@xjdrew
Last active December 21, 2015 15:29
Show Gist options
  • Save xjdrew/6327122 to your computer and use it in GitHub Desktop.
Save xjdrew/6327122 to your computer and use it in GitHub Desktop.
coroutine比较,lua的实现更科学一点。
function test1(co2)
print(12)
coroutine.resume(co2)
print(34)
coroutine.resume(co2)
end
function test2()
print(56)
coroutine.yield()
print(78)
end
local co1 = coroutine.create(test1)
local co2 = coroutine.create(test2)
coroutine.resume(co1, co2)
from greenlet import greenlet
def test1():
print 12
gr2.switch()
print 34
gr2.switch()
def test2():
print 56
gr1.switch()
print 78
gr1 = greenlet(test1)
gr2 = greenlet(test2)
gr1.switch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment