如果一个协程在Lua 5.1中没有被正确结束,会有多糟糕的影响呢?换句话说,如果一个协程被挂起但是我从未恢复它,那么它会在程序完成之前留下很多状态吗?
cor=coroutine.wrap(somefunc)
while true do
done=cor()
if done then -- coroutine exited with "return true"
break
else -- coroutine yielded with "coroutine.yield(false)"
if some_condition then break end
end
end
function somefunc()
-- do something
coroutine.yield(false)
-- do some more
return true
end
根据上面伪代码中的某些条件,协程可能永远不会被恢复,因此可能永远无法正确“结束”。
我可以对数十个协程执行此操作而无需担心吗?将协程保留在这种状态下是否安全?这是否费时?