Errors और Coroutine Helpers
एक coroutine के अंदर errors resume से catch होते हैं, और helper functions बताते हैं कि आप कहाँ हैं।
In this page:
Errors और Coroutine Helpers
अगर एक coroutine एक error raise करे, coroutine.resume false और error message return करता है और coroutine dead बन जाता है। coroutine.running current coroutine और एक boolean return करता है जो main thread के लिए true होता है। coroutine.isyieldable बताता है कि current code yield कर सकता है या नहीं, और Lua 5.3 में एक coroutine एक pcall के आर-पार yield कर सकता है।
Note:
main program खुद एक coroutine है, लेकिन यह yield नहीं कर सकता।
उदाहरण: Errors and coroutine helpers
local co = coroutine.create(function()
error("oops", 0)
end)
print(coroutine.resume(co))
print(coroutine.status(co))
print(select(2, coroutine.running()))
print(coroutine.isyieldable())
coroutine.wrap(function()
print(coroutine.isyieldable(), select(2, coroutine.running()))
local ok, v = pcall(function() return coroutine.yield("across pcall") end)
print(ok, v)
end)()
-- Output:
-- false oops
-- dead
-- true
-- false
-- true false
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- यह उम्मीद करना कि एक coroutine के अंदर एक error पूरे program को crash कर देगा
- error होने के बाद एक coroutine resume करना
- main thread से yield करने की कोशिश करना
चैप्टर सारांश
- resume errors catch करता है
- error होने वाला coroutine dead है
- coroutine.running current वाला identify करता है
- isyieldable check करता है कि yield allowed है या नहीं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: