#waker #async #thread #run-time #future #token #task

thread-waker

Waker implementation using current thread token

3 stable releases

1.2.0 Jan 21, 2025
1.1.0 Aug 24, 2024
1.0.0 Jul 27, 2024

#490 in Asynchronous

Download history 11/week @ 2024-12-08 1/week @ 2024-12-15 94/week @ 2025-01-19 5/week @ 2025-01-26 6/week @ 2025-02-02

105 downloads per month

BSL-1.0 license

5KB

thread-waker

Rust Crates.io Documentation

Waker implementation using current thread token.

This is useful to work with futures without actually employing runtime

Usage

use core::{time, task};
use std::thread;

use thread_waker::waker;

fn my_future(waker: task::Waker) {
    thread::sleep(time::Duration::from_millis(250));
    waker.wake();
}

let waker = waker(thread::current());

for _ in 0..4 {
    let waker = waker.clone();
    thread::spawn(move || my_future(waker));
    thread::park();
}

println!("I'm done!");

lib.rs:

Waker implementation using current thread token.

This is useful to work with futures without actually employing runtime

Usage

use core::{time, task};
use std::thread;

use thread_waker::waker;

fn my_future(waker: task::Waker) {
    thread::sleep(time::Duration::from_millis(250));
    waker.wake();
}

let waker = waker(thread::current());

for _ in 0..4 {
    let waker = waker.clone();
    thread::spawn(move || my_future(waker));
    thread::park();
}

println!("I'm done!");

No runtime deps

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy