Skip to content

Commit 5f595db

Browse files
authored
Merge pull request #30 from fereidani/master
improve performance by reusing the waker
2 parents 8418092 + 2378c89 commit 5f595db

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ use std::{
99
};
1010

1111
thread_local! {
12-
// A local reusable signal for each thread.
13-
static LOCAL_THREAD_SIGNAL: Arc<Signal> = Arc::new(Signal {
14-
owning_thread: thread::current(),
15-
});
12+
// A local reusable waker for each thread.
13+
static LOCAL_WAKER: Waker = {
14+
let signal = Arc::new(Signal {
15+
owning_thread: thread::current(),
16+
});
17+
Waker::from(signal)
18+
};
1619
}
1720

1821
#[cfg(feature = "macro")]
@@ -68,10 +71,9 @@ pub fn block_on<F: IntoFuture>(fut: F) -> F::Output {
6871
let mut fut = core::pin::pin!(fut.into_future());
6972

7073
// A signal used to wake up the thread for polling as the future moves to completion.
71-
LOCAL_THREAD_SIGNAL.with(|signal| {
72-
// Create a waker and a context to be passed to the future.
73-
let waker = Waker::from(Arc::clone(signal));
74-
let mut context = Context::from_waker(&waker);
74+
LOCAL_WAKER.with(|waker| {
75+
// Create a context to be passed to the future.
76+
let mut context = Context::from_waker(waker);
7577

7678
// Poll the future to completion.
7779
loop {

0 commit comments

Comments
 (0)