Skip to content

Instantly share code, notes, and snippets.

@ls0f
Created August 6, 2015 18:27
Show Gist options
  • Save ls0f/85817aaedbabea7e6cf6 to your computer and use it in GitHub Desktop.
Save ls0f/85817aaedbabea7e6cf6 to your computer and use it in GitHub Desktop.
lua-producer-consumer
#!/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