coroutine.wrap का उपयोग
wrap आपको एक plain function देता है जो हर बार call होने पर coroutine resume करता है।
In this page:
coroutine.wrap
coroutine.wrap(f) एक function return करता है जो हर call पर coroutine resume करता है और leading true के बिना yielded values return करता है। अगर अंदर एक error हो, यह status की तरह return होने की बजाय caller तक propagate हो जाती है। यह wrap को iterators के लिए convenient बनाता है।
Note:
जब आपको status चाहिए create इस्तेमाल करें, और जब आपको बस एक function चाहिए wrap इस्तेमाल करें।
उदाहरण: coroutine.wrap
local gen = coroutine.wrap(function()
for i = 1, 3 do coroutine.yield(i) end
end)
print(gen(), gen(), gen())
print(type(gen))
gen()
print(pcall(gen))
-- Output:
-- 1 2 3
-- function
-- false cannot resume dead coroutine
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- यह उम्मीद करना कि wrap एक coroutine object return करेगा
- यह उम्मीद करना कि errors false और एक message की तरह return होंगे
- खत्म होने के बाद एक wrapped coroutine call करना
चैप्टर सारांश
- wrap एक function return करता है
- कोई status boolean return नहीं होता
- Errors caller तक propagate होते हैं
- एक finished wrap call करना एक error raise करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: