-
Notifications
You must be signed in to change notification settings - Fork 52
A leaked Executor does not need to track active tasks #111
Description
A 'static Executor that has been leaked never has its Drop impl called. This may not be uncommon for use cases where an executor is initialized at startup and never dropped until program termination. In such a use case, the active field in the executor's state isn't really all that useful, as it's only used in the Drop impl and Executor::is_empty.
I understand the intent is to keep the API footprint of the crate fairly low, but would it be feasible to add something like this to the public API of the crate?
#[repr(transparent)]
pub struct LeakedExecutor(State);
impl Executor<'static> {
fn leak(self) -> &'static LeakedExecutor;
}
impl LeakedExecutor {
fn spawn<'a: 'static, T: Send + 'a, F: Future<Output = T> + 'a>(&self, fut: F) -> Task<T>;
async fn tick(&self);
async fn run(&self);
}LeakedExecutor should be able to omit all changes to active, and shouldn't require a lock when spawning or finishing tasks. Leaking is also not const, so the atomic check for the whether the state's initialized is also omitted from all calls to the type.