Created
August 6, 2015 18:27
-
-
Save ls0f/85817aaedbabea7e6cf6 to your computer and use it in GitHub Desktop.
lua-producer-consumer
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
#!/usr/local/bin/lua | |
function producer() | |
return coroutine.create(function() | |
while true do | |
local line = io.read() | |
coroutine.yield(line) | |
end | |
end) | |
end | |
function consumer(p) | |
while true do | |
local status,line = coroutine.resume(p) | |
if status then | |
io.write("INPUT:",line,"\n") | |
else | |
break | |
end | |
end | |
end | |
p = producer() | |
consumer(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment