Loosen lifetime requirements for single-threaded Scope::spawn to match the multi-threaded version. (#12073)
# Objective `Scope::spawn`, `Scope::spawn_on_external`, and `Scope::spawn_on_scope` have different signatures depending on whether the `multi-threaded` feature is enabled. The single-threaded version has a stricter signature that prevents sending the `Scope` itself to spawned tasks. ## Solution Changed the lifetime constraints in the single-threaded signatures from `'env` to `'scope` to match the multi-threaded version. This was split off from #11906.
This commit is contained in:
parent
a52b2518fc
commit
52f88e5672
@ -202,7 +202,7 @@ impl FakeTask {
|
|||||||
/// For more information, see [`TaskPool::scope`].
|
/// For more information, see [`TaskPool::scope`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Scope<'scope, 'env: 'scope, T> {
|
pub struct Scope<'scope, 'env: 'scope, T> {
|
||||||
executor: &'env async_executor::LocalExecutor<'env>,
|
executor: &'scope async_executor::LocalExecutor<'scope>,
|
||||||
// Vector to gather results of all futures spawned during scope run
|
// Vector to gather results of all futures spawned during scope run
|
||||||
results: &'env RefCell<Vec<Rc<RefCell<Option<T>>>>>,
|
results: &'env RefCell<Vec<Rc<RefCell<Option<T>>>>>,
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ impl<'scope, 'env, T: Send + 'env> Scope<'scope, 'env, T> {
|
|||||||
/// On the single threaded task pool, it just calls [`Scope::spawn_on_scope`].
|
/// On the single threaded task pool, it just calls [`Scope::spawn_on_scope`].
|
||||||
///
|
///
|
||||||
/// For more information, see [`TaskPool::scope`].
|
/// For more information, see [`TaskPool::scope`].
|
||||||
pub fn spawn<Fut: Future<Output = T> + 'env>(&self, f: Fut) {
|
pub fn spawn<Fut: Future<Output = T> + 'scope>(&self, f: Fut) {
|
||||||
self.spawn_on_scope(f);
|
self.spawn_on_scope(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ impl<'scope, 'env, T: Send + 'env> Scope<'scope, 'env, T> {
|
|||||||
/// On the single threaded task pool, it just calls [`Scope::spawn_on_scope`].
|
/// On the single threaded task pool, it just calls [`Scope::spawn_on_scope`].
|
||||||
///
|
///
|
||||||
/// For more information, see [`TaskPool::scope`].
|
/// For more information, see [`TaskPool::scope`].
|
||||||
pub fn spawn_on_external<Fut: Future<Output = T> + 'env>(&self, f: Fut) {
|
pub fn spawn_on_external<Fut: Future<Output = T> + 'scope>(&self, f: Fut) {
|
||||||
self.spawn_on_scope(f);
|
self.spawn_on_scope(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ impl<'scope, 'env, T: Send + 'env> Scope<'scope, 'env, T> {
|
|||||||
/// returned as a part of [`TaskPool::scope`]'s return value.
|
/// returned as a part of [`TaskPool::scope`]'s return value.
|
||||||
///
|
///
|
||||||
/// For more information, see [`TaskPool::scope`].
|
/// For more information, see [`TaskPool::scope`].
|
||||||
pub fn spawn_on_scope<Fut: Future<Output = T> + 'env>(&self, f: Fut) {
|
pub fn spawn_on_scope<Fut: Future<Output = T> + 'scope>(&self, f: Fut) {
|
||||||
let result = Rc::new(RefCell::new(None));
|
let result = Rc::new(RefCell::new(None));
|
||||||
self.results.borrow_mut().push(result.clone());
|
self.results.borrow_mut().push(result.clone());
|
||||||
let f = async move {
|
let f = async move {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user