Crate plunger

Crate plunger 

Source
Expand description

Plunger quickly unblocks your async tasks.

§Example

#[tokio::main]
async fn main() {
    let hash = "$argon2i$v=19$m=65536,t=1,p=1$c29tZXNhbHQAAAAAAAAAAA$+r0d29hqEB0yasKr55ZgICsQGSkl0v0kgwhd+U3wyRo";
    let password = "password";

    plunger::unblock(move || password_auth::verify_password(password, hash))
        .await
        .unwrap();
}

§Important notes

While the intent is to unblock the async runtime, this API might have to defensively block the runtime if cancellation occurs while the task is running.

We assume the following:

  1. Cancellation is rare
  2. Tasks run in the range of 100us to 1ms
  3. We can use block_in_place to reduce the impact of blocking when the tokio feature is enabled and using a multithreaded runtime.

Structs§

Plunger
Plunger quickly unblocks your async tasks.
Task
A task spawned into a Plunger
Worker
The worker state for a Plunger

Functions§

unblock
Run the CPU intensive code in a thread pool, avoiding blocking the async runtime.
unblock_until
Run the CPU intensive code in a thread pool, avoiding blocking the async runtime. The CPU intensive code can return Poll::Pending to efficiently allow yielding of the task if some fairness is desired.