Skip to content

pullEvent isn't resumed when run in a coroutine #1774

Answered by SquidDev
RobertBouillon asked this question in Q&A
Discussion options

You must be logged in to vote

So Lua doesn't really have any notion of coroutine scheduler. When you resume a coroutine, it runs that coroutine until it yields, and then restores control to the caller. This means resuming a coroutine is always going to be a "blocking" operation.

Of course, that doesn't mean you can't write your own! Typically what one does is wrap the whole program in a coroutine dispatch loop, and then run the main body of the program a coroutine. Then when you need to run background code, you can add a coroutine to the dispatcher.

There's a very simple example of this in this comment, but there's lots of alternative designs you can go for, like metis's await module1.

Footnotes

  1. Not really recommend…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RobertBouillon
Comment options

Answer selected by RobertBouillon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1773 on April 03, 2024 22:26.