-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yet another polling system sketch #3296
Yet another polling system sketch #3296
Conversation
def fromPollingSystem( | ||
name: String, | ||
system: PollingSystem): (EventLoop[system.Poller], () => Unit) = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A single-thread dispatcher from a polling system. I just tossed this together, I doubt it's any good.
I suspect that there will be objections to including this in CE. My argument for why we should have this is:
- implementing a good event dispatcher thread is non-trivial
- in the case when the WSTP does not have the desired polling system installed, to provide a fallback implementation a dispatcher thread will be necessary.
Haven't had a chance to read through this yet, but just at a high level, I do think that |
object EventLoop { | ||
def unapply[R](loop: EventLoop[Any])(ct: ClassTag[R]): Option[EventLoop[R]] = | ||
if (ct.runtimeClass.isAssignableFrom(loop.registrarTag.runtimeClass)) | ||
Some(loop.asInstanceOf[EventLoop[R]]) | ||
else | ||
None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So instead of this pattern match maybe we should expose this as IO.eventLoop
or something.
The idea of this sketch is to define a
trait EventLoop[Registrar] extends ExecutionContext
that provides access to a "registrar" (e.g. aSelector
orio_uring
) for registering callbacks on sockets etc., but only if you are currently running on thatExecutionContext
.Then, every
Network
is bound to a specificEventLoop
and must.evalOn(...)
to that loop whenever it needs to interact with the registrar. In the ideal scenario thisevalOn
will be a no-op (i.e. already running on the WSTP which the desired polling system installed).My goals were to:
Usual caveats: rough sketch, names subject to bikeshed, bla bla :)
Example usage:
Note: although here I've demoed it at the
Network
level, this can also be done at theSocket
level, which would be more friendly to FS2's current encoding ofNetwork
as a global implicit.