Skip to content

Conversation

@ysbaddaden
Copy link
Contributor

closes #15642

@yxhuvud
Copy link
Contributor

yxhuvud commented Apr 8, 2025

One could perhaps take a step back and consider if the marriage between wait groups and contexts should live in either of these or if it should be an entity of its own. As a concept it is getting pretty close to the concept of nurseries in the structured concurrency way of thinking.

Where are we going, in the greater path toward more sophisticated ways of setting up execution?

@ysbaddaden
Copy link
Contributor Author

IMO the nursery-like methods (.wait(&) and .spawn(&)) are the issue. Not the ability to specify a spawn context.

@ysbaddaden ysbaddaden added the pr:on-hold-do-not-merge This PR is on hold. Do not merge. label Apr 15, 2025
@BlobCodes
Copy link
Contributor

One could perhaps take a step back and consider if the marriage between wait groups and contexts should live in either of these or if it should be an entity of its own. As a concept it is getting pretty close to the concept of nurseries in the structured concurrency way of thinking.

I think this is a valid concern.
For example, we could instead have a fiber-local value (just like Scheduler.current) which controls where new fibers are spawned into, and then build a block-based DSL around that:

ctx = Fiber::ExecutionContext::SingleThreaded.new(name: "test")

# sets the fiber-local spawn-context var
# ensures this is rolled back on block exit
ctx.with_override do
  spawn do
    puts "context: #{Scheduler.current.name}"
  end
end

This should be a more generic interface and avoid having to add explicit execution context support to every concurrency-related shard and class.

@ysbaddaden ysbaddaden marked this pull request as draft May 6, 2025 08:58
@ysbaddaden
Copy link
Contributor Author

I'm closing. The idea to override the current spawn context is much better 👍

@ysbaddaden ysbaddaden closed this May 6, 2025
@github-project-automation github-project-automation bot moved this from Review to Done in Multi-threading May 6, 2025
@ysbaddaden ysbaddaden deleted the feature/execution-context-waitgroup-integration branch May 6, 2025 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add ExecutionContext support to WaitGroup

5 participants