task: relax 'static bound in LocalSet::block_on (#1882)

## 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]>
This commit is contained in:
Eliza Weisman
2019-12-02 16:43:33 -08:00
committed by GitHub
parent e87df0557d
commit 07451f8b94
+1 -2
View File
@@ -303,8 +303,7 @@ impl LocalSet {
/// [`spawn_blocking`]: ../blocking/fn.spawn_blocking.html
pub fn block_on<F>(&self, rt: &mut crate::runtime::Runtime, future: F) -> F::Output
where
F: Future + 'static,
F::Output: 'static,
F: Future,
{
let scheduler = self.scheduler.clone();
self.scheduler