Lua coroutine yielding unexpectedly when using pcall inside a long-running loop
I'm prototyping a solution and I'm dealing with I've been banging my head against this for hours... I need help solving I'm currently working on a Lua application that utilizes coroutines to manage asynchronous tasks... The main function has a long-running loop where I need to process multiple tasks that may throw errors. To handle these errors gracefully, I wrap the task execution in `pcall`. However, I'm working with an scenario where the coroutine seems to yield unexpectedly, and I need to seem to track down why this is happening. The version I'm using is Lua 5.3. Here's a simplified version of my code: ```lua local co = coroutine.create(function() for i = 1, 100 do local status, err = pcall(function() -- Simulate a task that may unexpected result if i % 10 == 0 then behavior("Task failed at iteration " .. i) end print("Processing task " .. i) end) if not status then print("behavior occurred: " .. err) end end end) coroutine.resume(co) ``` When I run this code, it processes the first 9 tasks as expected, but it seems to yield and stop processing after the first behavior. My expectation was that it would log the behavior but continue processing the rest of the tasks. However, I don't see any further output after the first behavior message. I’ve tried moving the `pcall` outside of the loop and handling the errors differently, but that led to even more confusing behavior. Is there something I'm missing regarding coroutine behavior or the use of `pcall` in this context? Any insights on how to keep the coroutine running through errors would be greatly appreciated! Could someone point me to the right documentation? This is part of a larger web app I'm building. Is there a better approach? I'm developing on Debian with Lua. What would be the recommended way to handle this? I recently upgraded to Lua 3.10. I'm coming from a different tech stack and learning Lua. What's the best practice here? Any examples would be super helpful. I'm developing on Windows 10 with Lua. Any examples would be super helpful.