Skip to content

Multiple state machines and coroutines #102

Answered by nsk90
Lukasmp3 asked this question in Q&A
Discussion options

You must be logged in to vote

No, newSingleThreadContext function just creates a thread and a CoroutineScope uses it to run coroutines inside. So it blocks calling thread only for a short time (means it is non-blocking)
Each call to newSingleThreadContext starts new thread. This is resource allocation so don't forget to close it when you are done with it's machine.

State machines that are attached to different threads such way, will run concurrently (to each other). As I understood that is what you need.

Keep in mind that thread allocation is not so cheap as coroutine startup. And if your method is called frequently you can get an error from OS that too many threads were created (about 200 I suppose). So thread pool s…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by Lukasmp3
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