Last active
December 21, 2015 15:29
-
-
Save xjdrew/6327122 to your computer and use it in GitHub Desktop.
coroutine比较,lua的实现更科学一点。
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
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) |
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
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