Skip to content

A leaked Executor does not need to track active tasks #111

@james7132

Description

@james7132

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions