Add ownPoller #4133
Conversation
| def accessPoller(cb: P => Unit): Unit | ||
|
|
||
| /** | ||
| * Returns `true` if it is safe to interact with this `Poller` |
There was a problem hiding this comment.
Can we add a note that it's always safe to return false here? So in other words, we tolerate false negatives, but we cannot tolerate false positives.
| var callback: Either[Throwable, Int] => Unit, | ||
| var next: CallbackNode | ||
| ) | ||
| private final class Callbacks { |
There was a problem hiding this comment.
We've built so many of these…
| } | ||
|
|
||
| private object PollingSystem { | ||
| trait PollerProvider[P] { |
There was a problem hiding this comment.
What about PollerContext or something in that vein? Kinda sucks that everything is "poller this" and "poller that". Could also be slightly more generic like WorkerContext or TLContext. ReferenceFrame is not inaccurate but more obscure.
There was a problem hiding this comment.
Renamed to PollingContext
| def ownPoller(poller: P): Boolean | ||
| } | ||
|
|
||
| private[unsafe] trait UnsealedPollingContext[P] extends PollingContext[P] |
There was a problem hiding this comment.
Before you tell me that private[unsafe] is the same as private since we are already in package unsafe, it's not:
private trait UnsealedPollingContext escapes its defining scope as part of type cats.effect.unsafe.UnsealedPollingContext[P]
This PR introduces a mechanism for checking if a given poller is "owned" by the current thread and thus is safe to interact with. This is useful primarily for cancelation, which may be requested from any thread, but can happy-path additional cleanup operations when on the owning thread.
The existing
accessPollerand newownPollermethods are now bundled up in aPollerProviderAPI.Finally,
SelectorSystemis improved to useownPollerto attempt to remove the linked list node for a canceled selection operation, instead of simply clearing it.Closes #4009.