Skip to content
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

Using ScheduledExecutorService for timeouts #145

Open
kciesielski opened this issue Jun 3, 2024 · 0 comments
Open

Using ScheduledExecutorService for timeouts #145

kciesielski opened this issue Jun 3, 2024 · 0 comments

Comments

@kciesielski
Copy link
Member

Currently, the timeout operation is implemented by racing given operation with a sleeping thread (BTW a similar approach is used in Cats Effect).
I was wondering if we could leverage a ScheduledExecutorService instead. It operates on a single threaded, which schedules and starts actual tasks. Netty uses this mechanism for timeouts in its IdleStateHandler. A scheduled task starts, emits an event and ends immediately. Then, Netty's internals handle the event in order to abort communication if a timeout occured.

In case of Ox, a scheduled task would start on a virtual thread (see hints in this Stack Overflow discussion). It would then call cancelation of the fork that's wrapped with timeout.

I don't know if such a solution will be more performant than racing with a sleeping thread, but I'm leaving this idea here for consideration. One certain issue is that the single-threaded pool for scheduling doesn't sound like something we want to create for each scope, but rather like a "runtime" that needs passing around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant