Skip to content

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Dec 2, 2019

Motivation

Currently, tokio::task::LocalSet's block_on method requires the
future to live for the 'static lifetime. However, this bound is not
required — the future is wrapped in a LocalFuture, and then passed
into Runtime::block_on, which does not require a 'static future.

This came up while updating tokio-compat to work with version 0.2. To
mimic the behavior of tokio 0.1's current_thread::Runtime::run, we
want to be able to have a runtime block on the recv future from an
mpsc channel indicating when the runtime is idle. To support !Send
futures, as the old current_thread::Runtime did, we must do so inside
of a LocalSet. However, with the current bounds, we cannot await an
mpsc::Receiver's recv future inside the LocalSet::block_on call.

Solution

This branch removes the unnecessary 'static bound.

Signed-off-by: Eliza Weisman [email protected]

Currently, `tokio::task::LocalSet`'s `block_on` method requires the
future to live for the 'static lifetime. However, this bound is not
required — the future is wrapped in a `LocalFuture`, and then passed
into `Runtime::block_on`, which does _not_ require a `'static` future.

This came up while updating `tokio-compat` to work with version 0.2. To
mimic the behavior of `tokio` 0.1's `current_thread::Runtime::run`, we
want to be able to have a runtime block on the `recv` future from an
mpsc channel indicating when the runtime is idle. To support `!Send`
futures, as the old `current_thread::Runtime` did, we must do so inside
of a `LocalSet`. However, with the current bounds, we cannot await an
`mpsc::Receiver`'s `recv` future inside the `LocalSet::block_on` call.

This branch removes the unnecessary `'static` bound.

Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw added the C-enhancement Category: A PR with an enhancement or bugfix. label Dec 2, 2019
@hawkw hawkw requested a review from a team December 2, 2019 23:54
@hawkw hawkw self-assigned this Dec 2, 2019
@hawkw
Copy link
Member Author

hawkw commented Dec 3, 2019

@carllerche Lucio pointed out on discord that this is a subtractive API change, so it could potentially be breaking — I can't really see any scenario where it could be a breaking change, but I wanted to see if you had any input?

@hawkw hawkw merged commit 07451f8 into master Dec 3, 2019
@carllerche carllerche deleted the eliza/non-static-local-block branch December 3, 2019 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A PR with an enhancement or bugfix.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants