lua协程

网络单请求处理:

coConsume = coroutine.create(
	function (filter, producer)
		while true do
			local stutas, msg = coroutine.resume(filter, producer)
			print('receive msg : ', msg)
		end
	end
)

coFilter = coroutine.create(
	function (producer)
		while true do
			local _, msg = coroutine.resume(producer)
			msg = msg..': '..string.len(msg)
			coroutine.yield(msg)
		end
	end
)

coProducer = coroutine.create(
	function ()
		while true do
			local msg = io.read()
			coroutine.yield(msg)
		end
	end
)
coroutine.resume(coConsume, coFilter, coProducer)
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页