-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
task: add Builder::{spawn_on, spawn_local_on, spawn_blocking_on}
#4683
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
`task::JoinSet` currently has both `spawn`/`spawn_local` methods, and `spawn_on`/`spawn_local_on` variants of these methods that take a reference to a runtime `Handle` or to a `LocalSet`, and spawn tasks on the provided runtime/`LocalSet`, rather than the current one. The `task::Builder` type is _also_ an API type that can spawn tasks, but it doesn't have `spawn_on` variants of its methods. It occurred to me that it would be nice to have similar APIs on `task::Builder`. This branch adds `task::Builder::spawn_on`, `task::Builder::spawn_local_on`, and `task::Builder::spawn_blocking_on` methods, similar to those on `JoinSet`. In addition, I did some refactoring of the internal spawning APIs --- there was a bit of duplicated code that this PR reduces.
it only incremented the spawner's refcount Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Noah-Kennedy
approved these changes
May 13, 2022
Was there a consideration to add a builder method for |
crapStone
pushed a commit
to Calciumdibromid/CaBr2
that referenced
this pull request
Jun 11, 2022
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dependencies | minor | `1.18.2` -> `1.19.1` | | [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dev-dependencies | minor | `1.18.2` -> `1.19.1` | --- ### Release Notes <details> <summary>tokio-rs/tokio</summary> ### [`v1.19.1`](https://github.com/tokio-rs/tokio/releases/tag/tokio-1.19.1) [Compare Source](tokio-rs/tokio@tokio-1.19.0...tokio-1.19.1) ##### 1.19.1 (June 5, 2022) This release fixes a bug in `Notified::enable`. ([#​4747]) [#​4747]: tokio-rs/tokio#4747 ### [`v1.19.0`](https://github.com/tokio-rs/tokio/releases/tag/tokio-1.19.0) [Compare Source](tokio-rs/tokio@tokio-1.18.2...tokio-1.19.0) ##### 1.19.0 (June 3, 2022) ##### Added - runtime: add `is_finished` method for `JoinHandle` and `AbortHandle` ([#​4709]) - runtime: make global queue and event polling intervals configurable ([#​4671]) - sync: add `Notified::enable` ([#​4705]) - sync: add `watch::Sender::send_if_modified` ([#​4591]) - sync: add resubscribe method to broadcast::Receiver ([#​4607]) - net: add `take_error` to `TcpSocket` and `TcpStream` ([#​4739]) ##### Changed - io: refactor out usage of Weak in the io handle ([#​4656]) ##### Fixed - macros: avoid starvation in `join!` and `try_join!` ([#​4624]) ##### Documented - runtime: clarify semantics of tasks outliving `block_on` ([#​4729]) - time: fix example for `MissedTickBehavior::Burst` ([#​4713]) ##### Unstable - metrics: correctly update atomics in `IoDriverMetrics` ([#​4725]) - metrics: fix compilation with unstable, process, and rt, but without net ([#​4682]) - task: add `#[track_caller]` to `JoinSet`/`JoinMap` ([#​4697]) - task: add `Builder::{spawn_on, spawn_local_on, spawn_blocking_on}` ([#​4683]) - task: add `consume_budget` for cooperative scheduling ([#​4498]) - task: add `join_set::Builder` for configuring `JoinSet` tasks ([#​4687]) - task: update return value of `JoinSet::join_one` ([#​4726]) [#​4498]: tokio-rs/tokio#4498 [#​4591]: tokio-rs/tokio#4591 [#​4607]: tokio-rs/tokio#4607 [#​4624]: tokio-rs/tokio#4624 [#​4656]: tokio-rs/tokio#4656 [#​4671]: tokio-rs/tokio#4671 [#​4682]: tokio-rs/tokio#4682 [#​4683]: tokio-rs/tokio#4683 [#​4687]: tokio-rs/tokio#4687 [#​4697]: tokio-rs/tokio#4697 [#​4705]: tokio-rs/tokio#4705 [#​4709]: tokio-rs/tokio#4709 [#​4713]: tokio-rs/tokio#4713 [#​4725]: tokio-rs/tokio#4725 [#​4726]: tokio-rs/tokio#4726 [#​4729]: tokio-rs/tokio#4729 [#​4739]: tokio-rs/tokio#4739 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [x] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Co-authored-by: cabr2-bot <cabr2.help@gmail.com> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1394 Reviewed-by: crapStone <crapstone@noreply.codeberg.org> Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org> Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
task::JoinSet
currently has bothspawn
/spawn_local
methods,and
spawn_on
/spawn_local_on
variants of these methods that take areference to a runtime
Handle
or to aLocalSet
, and spawn tasks onthe provided runtime/
LocalSet
, rather than the current one. Thetask::Builder
type is also an API type that can spawn tasks, but itdoesn't have
spawn_on
variants of its methods. It occurred to me thatit would be nice to have similar APIs on
task::Builder
.Solution
This branch adds
task::Builder::spawn_on
,task::Builder::spawn_local_on
, andtask::Builder::spawn_blocking_on
methods, similar to those on
JoinSet
. In addition, I did somerefactoring of the internal spawning APIs --- there was a bit of
duplicated code that this PR reduces.