In section 9.1 and 9.2 of Programming in Lua,
http://www.lua.org/pil/9.2.html,
there are some explanations of coroutines, and the example of consumers and producers. Also there is a comparison with pipes, a key point is: "The cost of switching between processes is high. With coroutines, the cost of switching between tasks is much smaller (roughly the same cost of a function call), so the writer and the reader can go hand in hand.