If I submit multiple requests to a Worker, it appe...
# kotlin-native
s
If I submit multiple requests to a Worker, it appears that the worker will only process a single request at a time. Is that correct? This is a fairly large restriction given that this is the primary method to move data between threads. Especially when I consider that I'd like to receive requests with coroutines, and those coroutines could end up suspending, and I'd like the worker to be doing other things during that time. Do I have the wrong frame of mind, or is there a better way that I should be approaching this?
k
Do you mean that the worker processes serially, or the caller thread blocks while trying to add a second job?
s
worker processes serially.
k
Pool of workers?
s
but then I can't have shared state...
k
How would you process something in parallel with a single thread?
s
If I send a message to a worker, and that worker delegates work to another thread (like a network request), then the worker will just sit there and do nothing until the network request returns, not processing any other requests.
I'd like the ability to have asynchronous behavior for the worker.
d
What you want is a pool of workers. A single worker will handle execution concurrently not in parallel, you should manage that yourself. I’m fairly certain this was done in the Worker example code.
s
As I mentioned above, that doesn't solve my problem. I want the ability to have shared state.
o
s
@olonho Requests still run serially, right? I see the ability to cancel work has been added, and also have future work. When future work is scheduled, do other requests run on the worker?