Skip to content

Add helpers for working with loop bound values #3215

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

glbrntt
Copy link
Contributor

@glbrntt glbrntt commented Apr 17, 2025

Motivation:

Isolating state to a given event loop is quite a common pattern. These types often provide sendable view APIs which do the event-loop dance for you. Writing these wrappers is somewhat repetitive (each method needs to do the dance) and requires a precondition.

We can make this simpler by providing helper methods on the loop bound types which do the event-loop dance.

Modifications:

Add three methods to NIOLoopBound and NIOLoopBoundBox:

  1. execute to execute a task with the loop bound value on the event loop
  2. submit to execute a task with the loop bound value on the event loop which returns a sendable value
  3. flatSubmit to execute a task with the loop bound value on the event loop which returns a future holding a sendable value

Result:

Easier to build sendable views of non-sendable types which are isolated to a given event loop.

Motivation:

Isolating state to a given event loop is quite a common pattern. These
types often provide sendable view APIs which do the event-loop dance
for you. Writing these wrappers is somewhat repetitive (each method
needs to do the dance) and requires a precondition.

We can make this simpler by providing helper methods on the loop bound
types which do the event-loop dance.

Modifications:

Add three methods to NIOLoopBound and NIOLoopBoundBox:
1. `execute` to execute a task with the loop bound value on the event
   loop
2. `submit` to execute a task with the loop bound value on the event
   loop which returns a sendable value
3. `flatSubmit` to execute a task with the loop bound value on the event
   loop which returns a future holding a sendable value

Result:

Easier to build sendable views of non-sendable types which are isolated
to a given event loop.
@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Apr 17, 2025
@glbrntt glbrntt enabled auto-merge (squash) April 17, 2025 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants