luvit / lit

Toolkit for developing, sharing, and running luvit/lua programs and libraries.
http://lit.luvit.io/
Apache License 2.0
245 stars 58 forks source link

coro-split: fixing coroutine resume before yielding #290

Closed Bilal2453 closed 3 years ago

Bilal2453 commented 3 years ago

Issue:

If you try the following code

require'coro-split'(
  function()
    print(1)
    print(2)
  end,
  function()
    print(3)
    print(4)
  end,
  function()
    print(5)
    print(6)
  end
)

it would error with the said error message after it executed everything successfully

cannot resume running coroutine

Explanation:

That's due to all tasks being spawned and completed before coroutine.yield have been reached, therefor the coroutine.resume in check would fail.

Solution: Basically make sure you only resume if yield have been executed (or tagged as so), otherwise return without yielding.

creationix commented 3 years ago

Love it, thanks!