| 1 | use std::{ |
| 2 | task::Waker, |
| 3 | thread::{self, Thread}, |
| 4 | }; |
| 5 | |
| 6 | use once_cell::sync::Lazy; |
| 7 | |
| 8 | /// Creates a dummy waker that does nothing. |
| 9 | pub(crate) fn empty_waker() -> Waker { |
| 10 | static WAKER: Lazy<Waker> = Lazy::new(|| waker_fn::waker_fn(move || {})); |
| 11 | |
| 12 | WAKER.clone() |
| 13 | } |
| 14 | |
| 15 | /// Creates a waker that unparks the current thread. |
| 16 | pub(crate) fn current_thread_waker() -> Waker { |
| 17 | thread_waker(thread::current()) |
| 18 | } |
| 19 | |
| 20 | /// Creates a waker that unparks a thread. |
| 21 | pub(crate) fn thread_waker(thread: Thread) -> Waker { |
| 22 | waker_fn::waker_fn(move || thread.unpark()) |
| 23 | } |