Skip to content

Commit

Permalink
remove old ReceiverWaker
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwuelker committed May 9, 2024
1 parent 998b92d commit 35222da
Showing 1 changed file with 0 additions and 47 deletions.
47 changes: 0 additions & 47 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,53 +1224,6 @@ where
}
}

enum ReceiverWaker {
/// The receiver is waiting synchronously. Its thread is parked.
#[cfg(feature = "std")]
Thread(thread::Thread),
/// The receiver is waiting asynchronously. Its task can be woken up with this `Waker`.
#[cfg(feature = "async")]
Task(task::Waker),
/// A little hack to not make this enum an uninhibitable type when no features are enabled.
#[cfg(not(any(feature = "async", feature = "std")))]
_Uninhabited,
}

impl ReceiverWaker {
#[cfg(feature = "std")]
pub fn current_thread() -> Self {
Self::Thread(thread::current())
}

#[cfg(feature = "async")]
pub fn task_waker(cx: &task::Context<'_>) -> Self {
Self::Task(cx.waker().clone())
}

pub fn unpark(self) {
match self {
#[cfg(feature = "std")]
ReceiverWaker::Thread(thread) => thread.unpark(),
#[cfg(feature = "async")]
ReceiverWaker::Task(waker) => waker.wake(),
#[cfg(not(any(feature = "async", feature = "std")))]
ReceiverWaker::_Uninhabited => unreachable!(),
}
}
}

#[cfg(not(loom))]
#[test]
fn receiver_waker_size() {
let expected: usize = match (cfg!(feature = "std"), cfg!(feature = "async")) {
(false, false) => 0,
(false, true) => 16,
(true, false) => 8,
(true, true) => 16,
};
assert_eq!(mem::size_of::<ReceiverWaker>(), expected);
}

#[cfg(all(feature = "std", feature = "async"))]
const RECEIVER_USED_SYNC_AND_ASYNC_ERROR: &str =
"Invalid to call a blocking receive method on oneshot::Receiver after it has been polled";
Expand Down

0 comments on commit 35222da

Please sign in to comment.