It's hard to discuss this in gitter due to timezone differences, so I made the issue.
The problem. I'm creating an actors library inspired by akka actors. And I want to:
I thought that I can use asyncdispatch like that: https://github.com/vegansk/nimactors/blob/489b07f1728cb5993ac9ef924c3899aee01bac7e/src/nimactors.nim#L72 , (example), but as it was explained here, I can't use poll without any pending callback, timers, handlers, it throws the exception.
So, can I implement the foresaid requirements using asyncdispatch? I can do it if it will not throw the exception if there is no pending operations. And I guess that it doesn't affect another async applications.
By the way, if we have only timers and callbacks, poll will eat 100% cpu, isn't it?
Quick thought: wouldn't moving the poll() after line 92 ensure that there is always at least one timer, callback or handle in the dispatcher?
@dom96, no. Async operations could be made in handler (lline 83) without using deferred messages
@vegansk I'm not sure I understand. You can call async operations before calling poll.
I need the loop that must handle messages that comes from another thread with the function defined somewhere. I can't call async operations untill some message will be received. I can't count that handler will call any async operation at all. It's up to the actor's creator
The biggest problem of your code is dependency on channels and async at the same time, because you can't wait for message from channels in asynchronous way. To resolve this i'm using pipes, you can use my implementation of asyncpipe.nim, or make your own implementation, but this of course will complicate your implementation (because you will need to make dispatcher for every thread and there will be some problems with automatic register/unregsiter descriptors with async queue)
Add pending operations presence check function, fixes #5155
@cheatfate, I don't want to use IPC for in-process communications. I think, I found the solution that can satisfy all: #5163
@vegansk to fully satisfy asynchronous behavior in threaded environment, you need to use it. Please check LWAN lightweight asynchronous multi-threaded event-based web server source code.
Also my wanted webserver POC uses same technique, and it outperforms asynchttpserver by 3x times on multi-core CPUs.
@cheatfate, thanks, i'll try it, but later, for now the project must be released