Skip to content

Commit

Permalink
Make sure Event/EventListener are Send/Sync (#59)
Browse files Browse the repository at this point in the history
Necessary to resolve failing tests in smol-rs/async-channel#59
  • Loading branch information
notgull committed May 23, 2023
1 parent 5380454 commit d6065ed
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@ impl<T> Drop for Event<T> {
/// kind of notification was delivered.
pub struct EventListener<T = ()>(Listener<T, Arc<Inner<T>>>);

unsafe impl<T: Send> Send for EventListener<T> {}
unsafe impl<T: Send> Sync for EventListener<T> {}

impl<T> fmt::Debug for EventListener<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("EventListener { .. }")
Expand Down Expand Up @@ -1132,3 +1135,13 @@ mod sync {
}
}
}

fn __test_send_and_sync() {
fn _assert_send<T: Send>() {}
fn _assert_sync<T: Sync>() {}

_assert_send::<Event<()>>();
_assert_sync::<Event<()>>();
_assert_send::<EventListener<()>>();
_assert_sync::<EventListener<()>>();
}

0 comments on commit d6065ed

Please sign in to comment.