-
Notifications
You must be signed in to change notification settings - Fork 190
Open
Description
Hello π
I have a question: from the spawn_local docs it is said that
pub fn spawn_local<T>(future: impl Future<Output = T> + 'static) -> Task<T> β
where
T: 'static,
---
Spawns a task onto the current single-threaded executor.
If called from a `LocalExecutor`, the task is spawned on it. Otherwise, this method panics.
...And the implementation basically just delegates the call into a LOCAL_EX executor spawn() method
pub fn spawn_local<T>(&self, future: impl Future<Output = T> + 'static) -> Task<T>
where
T: 'static,
{
#[cfg(not(feature = "native-tls"))]
return LOCAL_EX.with(|local_ex| Task::<T>(local_ex.spawn(future)));
#[cfg(feature = "native-tls")]
return Task::<T>(unsafe {
LOCAL_EX
.as_ref()
.expect("this thread doesn't have a LocalExecutor running")
.spawn(future)
});
}Would it be ok if that spawn() method on LocalExecutor struct just be made pub? So if the caller already have the LocalExecutor instance then they can just use it without any panic-risk (even though it would essentially never happens)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels