How could I check if a singlethreaded coroutine co...
# coroutines
How could I check if a singlethreaded coroutine context is currently executing or not?
I creatd it with newSingleThreadContext("name")
What is your use case for it?
I want a single thread to which I queue tasks, and if a task is already executing I don't want to queue another task, rather, do something else like printing a message
Essentially, I have 2 tasks, and they must go 1 at a time, if user tries to execute them in parallel I need to print a message.
So I thought to check "isActive" on a shared single thread context, but it doesn't work
Oh, I think that it’s completely wrong approach to queue coroutine tasks
You cannot use single thread for this
because coroutine do not block thread, this would make the whole idea of asynchronous API useless
so obviously you cannot limit amout of running coroutine on thread
instead of thread you can use actor, which is just a single coroutine that has message channel and process each of them sequentially
I don’t want to queue another task
If you don’t need queue, just 1 is running and all other are dropped, you can use
method which returns false if channel is already full and message will be just lost
yep makes sense