id
stringlengths
22
133
text
stringlengths
40
40.2k
arch
stringclasses
1 value
syntax
stringclasses
1 value
kind
stringclasses
4 values
repo
stringclasses
27 values
path
stringlengths
5
116
license
stringclasses
6 values
commit
stringlengths
40
40
source_host
stringclasses
1 value
category
stringclasses
16 values
source_url
stringlengths
85
196
line_start
int64
1
4.28k
line_end
int64
4
4.31k
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:7
fn cancel_acquire_releases_permits() { let s = Semaphore::new(10); s.try_acquire(4).expect("uncontended try_acquire succeeds"); assert_eq!(6, s.available_permits()); let mut acquire = task::spawn(s.acquire(8)); assert_pending!(acquire.poll()); assert_eq!(0, s.available_permits()); drop(acq...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
901f6d26c6aefd25a8f180e7a12ea8ed3c88ace2
github
async-runtime
https://github.com/tokio-rs/tokio/blob/901f6d26c6aefd25a8f180e7a12ea8ed3c88ace2/tokio/src/sync/tests/semaphore_batch.rs
241
283
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:6
assert!(acquire.is_woken()); assert_ready_err!(acquire.poll()); } #[test] fn close_semaphore_notifies_permit2() { let s = Semaphore::new(2); // Acquire a couple of permits assert_ready_ok!(task::spawn(s.acquire(1)).poll()); assert_ready_ok!(task::spawn(s.acquire(1)).poll()); let mut acquire3 ...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
b2ada60e701d5c9e6644cf8fc42a100774f8e23f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/src/sync/tests/semaphore_batch.rs
201
254
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:7
fn cancel_acquire_releases_permits() { let s = Semaphore::new(10); s.try_acquire(4).expect("uncontended try_acquire succeeds"); assert_eq!(6, s.available_permits()); let mut acquire = task::spawn(s.acquire(8)); assert_pending!(acquire.poll()); assert_eq!(0, s.available_permits()); drop(acq...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
b2ada60e701d5c9e6644cf8fc42a100774f8e23f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b2ada60e701d5c9e6644cf8fc42a100774f8e23f/tokio/src/sync/tests/semaphore_batch.rs
241
254
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:1
use crate::sync::batch_semaphore::Semaphore; use tokio_test::*; #[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; #[test] fn poll_acquire_one_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); // Polling for a pe...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f/tokio/src/sync/tests/semaphore_batch.rs
1
60
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:4
assert_eq!(s.available_permits(), 0); assert_err!(s.try_acquire(1)); s.release(1); assert_eq!(s.available_permits(), 1); assert_ok!(s.try_acquire(1)); s.release(1); assert_eq!(s.available_permits(), 1); } #[test] fn try_acquire_many_unavailable() { let s = Semaphore::new(5); // Acq...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f/tokio/src/sync/tests/semaphore_batch.rs
121
180
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:5
// Try to acquire the permit let mut acquire = task::spawn(s.acquire(1)); assert_pending!(acquire.poll()); s.release(1); assert!(acquire.is_woken()); assert_ready_ok!(acquire.poll()); } #[test] #[should_panic] #[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn vali...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/0dc62da21b0bffe113e2efa23f6da6ef4e36bf4f/tokio/src/sync/tests/semaphore_batch.rs
161
220
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:1
use crate::sync::batch_semaphore::Semaphore; use tokio_test::*; #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; #[test] fn poll_acquire_one_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); // Polling for a pe...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
6d3f92dddc510e9276191cfab1b0432ce8248589
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/src/sync/tests/semaphore_batch.rs
1
60
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:4
assert_eq!(s.available_permits(), 0); assert_err!(s.try_acquire(1)); s.release(1); assert_eq!(s.available_permits(), 1); assert_ok!(s.try_acquire(1)); s.release(1); assert_eq!(s.available_permits(), 1); } #[test] fn try_acquire_many_unavailable() { let s = Semaphore::new(5); // Acq...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
6d3f92dddc510e9276191cfab1b0432ce8248589
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/src/sync/tests/semaphore_batch.rs
121
180
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:5
// Try to acquire the permit let mut acquire = task::spawn(s.acquire(1)); assert_pending!(acquire.poll()); s.release(1); assert!(acquire.is_woken()); assert_ready_ok!(acquire.poll()); } #[test] #[should_panic] #[cfg(not(target_arch = "wasm32"))] // wasm currently doesn't support unwinding fn vali...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
6d3f92dddc510e9276191cfab1b0432ce8248589
github
async-runtime
https://github.com/tokio-rs/tokio/blob/6d3f92dddc510e9276191cfab1b0432ce8248589/tokio/src/sync/tests/semaphore_batch.rs
161
220
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:1
use crate::sync::batch_semaphore::Semaphore; use tokio_test::*; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::wasm_bindgen_test as test; #[test] fn poll_acquire_one_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); // Polling for a permit succeeds immediately ...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
2747043f6f7e0870cc5aa72c146dfae9543c5ba8
github
async-runtime
https://github.com/tokio-rs/tokio/blob/2747043f6f7e0870cc5aa72c146dfae9543c5ba8/tokio/src/sync/tests/semaphore_batch.rs
1
60
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:1
use crate::sync::batch_semaphore::Semaphore; use tokio_test::*; #[test] fn poll_acquire_one_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); // Polling for a permit succeeds immediately assert_ready_ok!(task::spawn(s.acquire(1)).poll()); assert_eq!(s.available_per...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
9264b837d897dcdf974703a6739132b995e669bc
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9264b837d897dcdf974703a6739132b995e669bc/tokio/src/sync/tests/semaphore_batch.rs
1
60
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:2
let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); assert_ok!(s.try_acquire(5)); assert_eq!(s.available_permits(), 95); assert_ok!(s.try_acquire(5)); assert_eq!(s.available_permits(), 90); } #[test] fn poll_acquire_one_unavailable() { let s = Semaphore::new(1); // Acqui...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
9264b837d897dcdf974703a6739132b995e669bc
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9264b837d897dcdf974703a6739132b995e669bc/tokio/src/sync/tests/semaphore_batch.rs
41
100
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:3
assert_eq!(s.available_permits(), 4); // Try to acquire the second permit let mut acquire_2 = task::spawn(s.acquire(5)); assert_pending!(acquire_2.poll()); assert_eq!(s.available_permits(), 0); // Try to acquire the third permit let mut acquire_3 = task::spawn(s.acquire(3)); assert_pending...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
9264b837d897dcdf974703a6739132b995e669bc
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9264b837d897dcdf974703a6739132b995e669bc/tokio/src/sync/tests/semaphore_batch.rs
81
140
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:4
s.release(1); assert_eq!(s.available_permits(), 1); assert_ok!(s.try_acquire(1)); s.release(1); assert_eq!(s.available_permits(), 1); } #[test] fn try_acquire_many_unavailable() { let s = Semaphore::new(5); // Acquire the first permit assert_ok!(s.try_acquire(1)); assert_eq!(s.availa...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
9264b837d897dcdf974703a6739132b995e669bc
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9264b837d897dcdf974703a6739132b995e669bc/tokio/src/sync/tests/semaphore_batch.rs
121
180
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:5
s.release(1); assert!(acquire.is_woken()); assert_ready_ok!(acquire.poll()); } #[test] #[should_panic] fn validates_max_permits() { use std::usize; Semaphore::new((usize::MAX >> 2) + 1); } #[test] fn close_semaphore_prevents_acquire() { let s = Semaphore::new(5); s.close(); assert_eq!(5,...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
9264b837d897dcdf974703a6739132b995e669bc
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9264b837d897dcdf974703a6739132b995e669bc/tokio/src/sync/tests/semaphore_batch.rs
161
220
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:6
#[test] fn close_semaphore_notifies_permit2() { let s = Semaphore::new(2); // Acquire a couple of permits assert_ready_ok!(task::spawn(s.acquire(1)).poll()); assert_ready_ok!(task::spawn(s.acquire(1)).poll()); let mut acquire3 = task::spawn(s.acquire(1)); let mut acquire4 = task::spawn(s.acqui...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
9264b837d897dcdf974703a6739132b995e669bc
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9264b837d897dcdf974703a6739132b995e669bc/tokio/src/sync/tests/semaphore_batch.rs
201
250
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:7
let mut acquire = task::spawn(s.acquire(8)); assert_pending!(acquire.poll()); assert_eq!(0, s.available_permits()); drop(acquire); assert_eq!(6, s.available_permits()); assert_ok!(s.try_acquire(6)); }
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
9264b837d897dcdf974703a6739132b995e669bc
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9264b837d897dcdf974703a6739132b995e669bc/tokio/src/sync/tests/semaphore_batch.rs
241
250
tokio-rs/tokio:tokio/src/sync/tests/semaphore_batch.rs:6
#[test] fn close_semaphore_notifies_permit2() { let s = Semaphore::new(2); // Acquire a couple of permits assert_ready_ok!(task::spawn(s.acquire(1)).poll()); assert_ready_ok!(task::spawn(s.acquire(1)).poll()); let mut acquire3 = task::spawn(s.acquire(1)); let mut acquire4 = task::spawn(s.acqui...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_batch.rs
MIT
acf8a7da7a64bf08d578db9a9836a8e061765314
github
async-runtime
https://github.com/tokio-rs/tokio/blob/acf8a7da7a64bf08d578db9a9836a8e061765314/tokio/src/sync/tests/semaphore_batch.rs
201
250
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:1
use crate::sync::semaphore_ll::{Permit, Semaphore}; use tokio_test::*; #[test] fn poll_acquire_one_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); // Polling for a permit succeeds immediately let mut permit = task::spawn(Permit::new()); assert!(!permit.is_acquire...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
1
60
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:2
assert_ready_ok!(permit.enter(|cx, mut p| p.poll_acquire(cx, 5, &s))); assert_eq!(s.available_permits(), 95); assert!(permit.is_acquired()); // Polling for a larger number of permits acquires more assert_ready_ok!(permit.enter(|cx, mut p| p.poll_acquire(cx, 8, &s))); assert_eq!(s.available_permits(...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
41
100
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:3
assert!(permit.is_acquired()); // Polling again on the same waiter does not claim a new permit assert_ok!(permit.try_acquire(5, &s)); assert_eq!(s.available_permits(), 95); assert!(permit.is_acquired()); } #[test] fn poll_acquire_one_unavailable() { let s = Semaphore::new(1); let mut permit_1...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
81
140
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:4
assert_ready_ok!(permit.enter(|cx, mut p| p.poll_acquire(cx, 1, &s))); assert_eq!(s.available_permits(), 0); permit.forget(1); assert_eq!(s.available_permits(), 0); } #[test] fn forget_waiting() { let s = Semaphore::new(0); // Polling for a permit succeeds immediately let mut permit = task::...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
121
180
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:5
permit_2.enter(|cx, mut p| { // Try to acquire the second permit assert_pending!(p.poll_acquire(cx, 5, &s)); }); assert_eq!(s.available_permits(), 0); permit_3.enter(|cx, mut p| { // Try to acquire the third permit assert_pending!(p.poll_acquire(cx, 3, &s)); }); pe...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
161
220
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:6
assert_eq!(s.available_permits(), 0); assert_err!(permit_2.try_acquire(1, &s)); permit_1.release(1, &s); assert_eq!(s.available_permits(), 1); assert_ok!(permit_2.try_acquire(1, &s)); permit_2.release(1, &s); assert_eq!(s.available_permits(), 1); } #[test] fn try_acquire_many_unavailable() ...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
201
260
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:7
let s = Semaphore::new(0); assert_eq!(s.available_permits(), 0); let mut permit = task::spawn(Permit::new()); // Try to acquire the permit permit.enter(|cx, mut p| { assert_pending!(p.poll_acquire(cx, 1, &s)); }); s.add_permits(1); assert!(permit.is_woken()); assert_ready_ok!...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
241
300
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:8
#[test] fn close_semaphore_notifies_permit1() { let s = Semaphore::new(0); let mut permit = task::spawn(Permit::new()); assert_pending!(permit.enter(|cx, mut p| p.poll_acquire(cx, 1, &s))); s.close(); assert!(permit.is_woken()); assert_ready_err!(permit.enter(|cx, mut p| p.poll_acquire(cx, 1,...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
281
340
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:9
assert_eq!(1, s.available_permits()); assert_ready_err!(permit1.enter(|cx, mut p| p.poll_acquire(cx, 1, &s))); permit2.release(1, &s); assert_eq!(2, s.available_permits()); } #[test] fn poll_acquire_additional_permits_while_waiting_before_assigned() { let s = Semaphore::new(1); let mut permit =...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
321
380
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:10
assert_ok!(permit.enter(|_, mut p| p.try_acquire(2, &s))); } #[test] fn poll_acquire_additional_permits_while_waiting_after_assigned_success() { let s = Semaphore::new(1); let mut permit = task::spawn(Permit::new()); assert_pending!(permit.enter(|cx, mut p| p.poll_acquire(cx, 2, &s))); s.add_permits...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
361
420
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:11
let mut permit = task::spawn(Permit::new()); assert_pending!(permit.enter(|cx, mut p| p.poll_acquire(cx, 2, &s))); assert_eq!(s.available_permits(), 0); assert_ready_ok!(permit.enter(|cx, mut p| p.poll_acquire(cx, 1, &s))); assert_eq!(s.available_permits(), 0); } #[test] fn poll_acquire_fewer_permits...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
401
460
tokio-rs/tokio:tokio/src/sync/tests/semaphore_ll.rs:12
assert_pending!(permit.enter(|cx, mut p| p.poll_acquire(cx, 2, &s))); s.add_permits(1); assert_eq!(0, s.available_permits()); permit.release(1, &s); assert_ready_ok!(permit.enter(|cx, mut p| p.poll_acquire(cx, 1, &s))); assert_eq!(s.available_permits(), 0); } #[test] fn forget_partial_2() { ...
rust
rust
testsuite
tokio-rs/tokio
tokio/src/sync/tests/semaphore_ll.rs
MIT
efcbf9613f2d5048550f9c828e3be422644f1391
github
async-runtime
https://github.com/tokio-rs/tokio/blob/efcbf9613f2d5048550f9c828e3be422644f1391/tokio/src/sync/tests/semaphore_ll.rs
441
470
tokio-rs/tokio:tokio/src/sync/watch.rs:5
//! [`Sender::is_closed`]: crate::sync::watch::Sender::is_closed //! [`Sender::closed`]: crate::sync::watch::Sender::closed //! [`Sender::subscribe()`]: crate::sync::watch::Sender::subscribe use crate::sync::notify::Notify; use crate::task::coop::cooperative; use crate::loom::sync::atomic::AtomicUsize; use crate::loo...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
161
220
tokio-rs/tokio:tokio/src/sync/watch.rs:6
impl<T> Clone for Sender<T> { fn clone(&self) -> Self { self.shared.ref_count_tx.fetch_add(1, Relaxed); Self { shared: self.shared.clone(), } } } impl<T: Default> Default for Sender<T> { fn default() -> Self { Self::new(T::default()) } } /// Returns a refer...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
201
260
tokio-rs/tokio:tokio/src/sync/watch.rs:8
/// assert_eq!(*received, "goodbye"); /// assert!(received.has_changed()); /// // Release the read lock when leaving this scope. /// } /// /// // Now the value has already been marked as seen and could /// // never be modified again (after the sender has been dropped). /// assert...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
281
340
tokio-rs/tokio:tokio/src/sync/watch.rs:9
let state = self.state.load(); f.debug_struct("Shared") .field("value", &self.value) .field("version", &state.version()) .field("is_closed", &state.is_closed()) .field("ref_count_rx", &self.ref_count_rx) .finish() } } pub mod error { //! Watch...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
321
380
tokio-rs/tokio:tokio/src/sync/watch.rs:10
// ===== impl RecvError ===== impl fmt::Display for RecvError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "channel closed") } } impl Error for RecvError {} } mod big_notify { use super::Notify; use crate::sync::notify::Notified; // T...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
361
420
tokio-rs/tokio:tokio/src/sync/watch.rs:11
next: std::sync::atomic::AtomicUsize::new(0), inner: Default::default(), } } pub(super) fn notify_waiters(&self) { for notify in &self.inner { notify.notify_waiters(); } } /// This function implements the case where ra...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
401
460
tokio-rs/tokio:tokio/src/sync/watch.rs:12
/// Snapshot of the state. The first bit is used as the CLOSED bit. /// The remaining bits are used as the version. /// /// The CLOSED bit tracks whether all senders have been dropped. Dropping all /// receivers does not set it. #[derive(Copy, Clone, Debug)] pub(super) struct StateSnapshot(usize...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
441
500
tokio-rs/tokio:tokio/src/sync/watch.rs:13
} impl AtomicState { /// Create a new `AtomicState` that is not closed and which has the /// version set to `Version::INITIAL`. pub(super) fn new() -> Self { AtomicState(AtomicUsize::new(Version::INITIAL.0)) } /// Load the current value of the state. ///...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
481
540
tokio-rs/tokio:tokio/src/sync/watch.rs:14
/// Only the last value sent is made available to the [`Receiver`] half. All /// intermediate values are dropped. /// /// # Examples /// /// The following example prints `hello! world! `. /// /// ``` /// use tokio::sync::watch; /// use tokio::time::{Duration, sleep}; /// /// # async fn dox() -> Result<(), Box<dyn std::...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
521
580
tokio-rs/tokio:tokio/src/sync/watch.rs:15
notify_tx: Notify::new(), }); let tx = Sender { shared: shared.clone(), }; let rx = Receiver { shared, version: Version::INITIAL, }; (tx, rx) } impl<T> Receiver<T> { fn from_shared(version: Version, shared: Arc<Shared<T>>) -> Self { // No synchronization n...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
561
620
tokio-rs/tokio:tokio/src/sync/watch.rs:19
/// /// ## Closed channel example /// /// ``` /// use tokio::sync::watch; /// /// # #[tokio::main(flavor = "current_thread")] /// # async fn main() { /// let (tx, rx) = watch::channel("hello"); /// tx.send("goodbye").unwrap(); /// /// drop(tx); /// /// // The channel ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
721
780
tokio-rs/tokio:tokio/src/sync/watch.rs:23
/// sleep(Duration::from_secs(1)).await; /// tx.send("goodbye").unwrap(); /// }); /// /// assert!(rx.wait_for(|val| *val == "goodbye").await.is_ok()); /// assert_eq!(*rx.borrow(), "goodbye"); /// } /// ``` pub async fn wait_for( &mut self, f: i...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
881
940
tokio-rs/tokio:tokio/src/sync/watch.rs:24
// Forward the panic to the caller. panic::resume_unwind(panicked); // Unreachable } }; } } if closed { return Err(error::RecvError(())); } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
921
980
tokio-rs/tokio:tokio/src/sync/watch.rs:25
fn maybe_changed<T>( shared: &Shared<T>, version: &mut Version, ) -> Option<Result<(), error::RecvError>> { // Load the version from the state let state = shared.state.load(); let new_version = state.version(); if *version != new_version { // Observe the new version and return *...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
961
1,020
tokio-rs/tokio:tokio/src/sync/watch.rs:26
} } impl<T> Clone for Receiver<T> { fn clone(&self) -> Self { let version = self.version; let shared = self.shared.clone(); Self::from_shared(version, shared) } } impl<T> Drop for Receiver<T> { fn drop(&mut self) { // No synchronization necessary as this is only used as a ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
1,001
1,060
tokio-rs/tokio:tokio/src/sync/watch.rs:30
/// assert!(!state_rx.has_changed().unwrap()); /// assert!(state_tx.send_if_modified(inc_counter_if_odd)); /// assert!(state_rx.has_changed().unwrap()); /// assert_eq!(state_rx.borrow_and_update().counter, 2); /// /// assert!(!state_rx.has_changed().unwrap()); /// assert!(!state_tx.send_if_modif...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
1,161
1,220
tokio-rs/tokio:tokio/src/sync/watch.rs:31
// // Incrementing the version counter while holding the lock ensures // that receivers are able to figure out the version number of the // value they are currently looking at. drop(lock); } self.shared.notify_rx.notify_waiters(); true } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
1,201
1,260
tokio-rs/tokio:tokio/src/sync/watch.rs:37
/// Returns `true` if senders belong to the same channel. /// /// # Examples /// /// ``` /// let (tx, rx) = tokio::sync::watch::channel(true); /// let tx2 = tx.clone(); /// assert!(tx.same_channel(&tx2)); /// /// let (tx3, rx3) = tokio::sync::watch::channel(true); /// assert!(!tx...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
1,441
1,500
tokio-rs/tokio:tokio/src/sync/watch.rs:38
// test for https://github.com/tokio-rs/tokio/issues/3168 #[test] fn watch_spurious_wakeup() { loom::model(|| { let (send, mut recv) = crate::sync::watch::channel(0i32); send.send(1).unwrap(); let send_thread = thread::spawn(move || { send.send(2).un...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
1,481
1,540
tokio-rs/tokio:tokio/src/sync/watch.rs:39
assert!(send.borrow().eq(&0)); assert!(recv.borrow().eq(&0)); send.send(1).unwrap(); assert!(send.borrow().eq(&1)); let send_thread = thread::spawn(move || { send.send(2).unwrap(); send }); recv.changed().now_or_n...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/sync/watch.rs
1,521
1,556
tokio-rs/tokio:tokio/src/sync/watch.rs:8
/// assert_eq!(*received, "goodbye"); /// assert!(received.has_changed()); /// // Release the read lock when leaving this scope. /// } /// /// // Now the value has already been marked as seen and could /// // never be modified again (after the sender has been ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
b9b532485bbb879042a1bd2ef40a50e6c1d15bb6
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b9b532485bbb879042a1bd2ef40a50e6c1d15bb6/tokio/src/sync/watch.rs
281
340
tokio-rs/tokio:tokio/src/sync/watch.rs:19
/// /// ## Closed channel example /// /// ``` /// use tokio::sync::watch; /// /// #[tokio::main] /// async fn main() { /// let (tx, rx) = watch::channel("hello"); /// tx.send("goodbye").unwrap(); /// /// drop(tx); /// /// // The channel is closed /...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
b9b532485bbb879042a1bd2ef40a50e6c1d15bb6
github
async-runtime
https://github.com/tokio-rs/tokio/blob/b9b532485bbb879042a1bd2ef40a50e6c1d15bb6/tokio/src/sync/watch.rs
721
780
tokio-rs/tokio:tokio/src/sync/watch.rs:3
//! sleep(Duration::from_millis(100)).await; //! tx.send("world")?; //! # Ok(()) //! # } //! ``` //! //! # Closing //! //! [`Sender::is_closed`] and [`Sender::closed`] allow the producer to detect //! when all [`Receiver`] handles have been dropped. This indicates that there //! is no further interest in the values bei...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
81
140
tokio-rs/tokio:tokio/src/sync/watch.rs:4
use std::mem; use std::ops; use std::panic; /// Receives values from the associated [`Sender`](struct@Sender). /// /// Instances are created by the [`channel`](fn@channel) function. /// /// To turn this receiver into a `Stream`, you can use the [`WatchStream`] /// wrapper. /// /// [`WatchStream`]: https://docs.rs/toki...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
121
180
tokio-rs/tokio:tokio/src/sync/watch.rs:7
self.has_changed } } struct Shared<T> { /// The most recent value. value: RwLock<T>, /// The current version. /// /// The lowest bit represents a "closed" state. The rest of the bits /// represent the current version. state: AtomicState, /// Tracks the number of `Receiver` instanc...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
241
300
tokio-rs/tokio:tokio/src/sync/watch.rs:8
//! Watch error types. use std::error::Error; use std::fmt; /// Error produced when sending a value fails. #[derive(PartialEq, Eq, Clone, Copy)] pub struct SendError<T>(pub T); // ===== impl SendError ===== impl<T> fmt::Debug for SendError<T> { fn fmt(&self, f: &mut fmt::Formatte...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
281
340
tokio-rs/tokio:tokio/src/sync/watch.rs:9
mod big_notify { use super::Notify; use crate::sync::notify::Notified; // To avoid contention on the lock inside the `Notify`, we store multiple // copies of it. Then, we use either circular access or randomness to spread // out threads over different `Notify` objects. // // Some simple ben...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
321
380
tokio-rs/tokio:tokio/src/sync/watch.rs:10
/// This function implements the case where randomness is not available. #[cfg(not(all(not(loom), feature = "sync", any(feature = "rt", feature = "macros"))))] pub(super) fn notified(&self) -> Notified<'_> { let i = self.next.fetch_add(1, std::sync::atomic::Ordering::Relaxed) % 8; ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
361
420
tokio-rs/tokio:tokio/src/sync/watch.rs:11
/// The `Sender` uses `Release` ordering for storing a new state /// and the `Receiver`s use `Acquire` ordering for loading the /// current state. This ensures that written values are seen by /// the `Receiver`s for a proper handover. #[derive(Debug)] pub(super) struct AtomicState(AtomicUsize); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
401
460
tokio-rs/tokio:tokio/src/sync/watch.rs:13
/// # async fn dox() -> Result<(), Box<dyn std::error::Error>> { /// let (tx, mut rx) = watch::channel("hello"); /// /// tokio::spawn(async move { /// // Use the equivalent of a "do-while" loop so the initial value is /// // processed before awaiting the `changed()` future. /// loop { /// println!("...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
481
540
tokio-rs/tokio:tokio/src/sync/watch.rs:21
/// use tokio::sync::watch; /// use tokio::time::{sleep, Duration}; /// /// #[tokio::main(flavor = "current_thread", start_paused = true)] /// async fn main() { /// let (tx, mut rx) = watch::channel("hello"); /// /// tokio::spawn(async move { /// sleep(Duration::from_secs...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
801
860
tokio-rs/tokio:tokio/src/sync/watch.rs:22
return Ok(Ref { inner, has_changed }); } Ok(false) => { // Skip the value. } Err(panicked) => { // Drop the read-lock to avoid poisoning it. ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
841
900
tokio-rs/tokio:tokio/src/sync/watch.rs:23
cfg_process_driver! { pub(crate) fn try_has_changed(&mut self) -> Option<Result<(), error::RecvError>> { maybe_changed(&self.shared, &mut self.version) } } } fn maybe_changed<T>( shared: &Shared<T>, version: &mut Version, ) -> Option<Result<(), error::RecvError>> { // Load t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
881
940
tokio-rs/tokio:tokio/src/sync/watch.rs:24
let notified = shared.notify_rx.notified(); if let Some(ret) = maybe_changed(shared, version) { return ret; } notified.await; // loop around again in case the wake-up was spurious } } impl<T> Clone for Receiver<T> { fn clone(&self) -> Self { let version = s...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
921
980
tokio-rs/tokio:tokio/src/sync/watch.rs:28
/// state.counter += 1; /// return true; /// } /// false /// }; /// /// assert_eq!(state_rx.borrow().counter, 1); /// /// assert!(!state_rx.has_changed().unwrap()); /// assert!(state_tx.send_if_modified(inc_counter_if_odd)); /// assert!(state_rx.has_change...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/watch.rs:29
panic::resume_unwind(panicked); // Unreachable } }; self.shared.state.increment_version_while_locked(); // Release the write lock. // // Incrementing the version counter while holding the lock ensures // that r...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
1,121
1,180
tokio-rs/tokio:tokio/src/sync/watch.rs:31
/// ``` pub fn is_closed(&self) -> bool { self.receiver_count() == 0 } /// Completes when all receivers have dropped. /// /// This allows the producer to get notified when interest in the produced /// values is canceled and immediately stop doing work. Once a channel is /// closed, ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
1,201
1,260
tokio-rs/tokio:tokio/src/sync/watch.rs:35
/// assert_eq!(2, tx1.sender_count()); /// assert_eq!(2, tx2.sender_count()); /// } /// ``` pub fn sender_count(&self) -> usize { self.shared.ref_count_tx.load(Relaxed) } /// Returns `true` if senders belong to the same channel. /// /// # Examples /// /// ``` ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
1,361
1,420
tokio-rs/tokio:tokio/src/sync/watch.rs:36
self.inner.deref() } } #[cfg(all(test, loom))] mod tests { use futures::future::FutureExt; use loom::thread; // test for https://github.com/tokio-rs/tokio/issues/3168 #[test] fn watch_spurious_wakeup() { loom::model(|| { let (send, mut recv) = crate::sync::watch::channel(0i...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
1,401
1,460
tokio-rs/tokio:tokio/src/sync/watch.rs:37
send_thread.join().unwrap(); }); } #[test] fn watch_borrow() { loom::model(|| { let (send, mut recv) = crate::sync::watch::channel(0i32); assert!(send.borrow().eq(&0)); assert!(recv.borrow().eq(&0)); send.send(1).unwrap(); assert...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
5f3f5b0be4ec933aed2290ea9d929b5daadae321
github
async-runtime
https://github.com/tokio-rs/tokio/blob/5f3f5b0be4ec933aed2290ea9d929b5daadae321/tokio/src/sync/watch.rs
1,441
1,484
tokio-rs/tokio:tokio/src/sync/watch.rs:3
//! sleep(Duration::from_millis(100)).await; //! tx.send("world")?; //! # Ok(()) //! # } //! ``` //! //! # Closing //! //! [`Sender::is_closed`] and [`Sender::closed`] allow the producer to detect //! when all [`Receiver`] handles have been dropped. This indicates that there //! is no further interest in the values bei...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/watch.rs
81
140
tokio-rs/tokio:tokio/src/sync/watch.rs:10
/// This function implements the case where randomness is not available. #[cfg(not(all(not(loom), feature = "sync", any(feature = "rt", feature = "macros"))))] pub(super) fn notified(&self) -> Notified<'_> { let i = self.next.fetch_add(1, std::sync::atomic::Ordering::Relaxed) % 8; ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/watch.rs
361
420
tokio-rs/tokio:tokio/src/sync/watch.rs:23
cfg_process_driver! { pub(crate) fn try_has_changed(&mut self) -> Option<Result<(), error::RecvError>> { maybe_changed(&self.shared, &mut self.version) } } } fn maybe_changed<T>( shared: &Shared<T>, version: &mut Version, ) -> Option<Result<(), error::RecvError>> { // Load t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
605ef578df04f12a951060dc3b2fb930f6f379fe
github
async-runtime
https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/sync/watch.rs
881
940
tokio-rs/tokio:tokio/src/sync/watch.rs:3
//! sleep(Duration::from_millis(100)).await; //! tx.send("world")?; //! # Ok(()) //! # } //! ``` //! //! # Closing //! //! [`Sender::is_closed`] and [`Sender::closed`] allow the producer to detect //! when all [`Receiver`] handles have been dropped. This indicates that there //! is no further interest in the values bei...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
e066431c94768ee75876cbf6a9d9ef685730c60f
github
async-runtime
https://github.com/tokio-rs/tokio/blob/e066431c94768ee75876cbf6a9d9ef685730c60f/tokio/src/sync/watch.rs
81
140
tokio-rs/tokio:tokio/src/sync/watch.rs:21
/// let mut rx2 = tx.subscribe(); /// /// // in place of changed we have use `wait_for` /// // which would automatically check the current value /// // and wait for changes until the closure returns true. /// assert!(rx2.wait_for(|val| *val == "goodbye").await.is_ok()); /// ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
9cc4a81678ffb423cf89c12b08241272c1b6ecb1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9cc4a81678ffb423cf89c12b08241272c1b6ecb1/tokio/src/sync/watch.rs
801
860
tokio-rs/tokio:tokio/src/sync/watch.rs:22
drop(inner); // Forward the panic to the caller. panic::resume_unwind(panicked); // Unreachable } }; } } if closed { return Err(error::...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
9cc4a81678ffb423cf89c12b08241272c1b6ecb1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9cc4a81678ffb423cf89c12b08241272c1b6ecb1/tokio/src/sync/watch.rs
841
900
tokio-rs/tokio:tokio/src/sync/watch.rs:23
fn maybe_changed<T>( shared: &Shared<T>, version: &mut Version, ) -> Option<Result<(), error::RecvError>> { // Load the version from the state let state = shared.state.load(); let new_version = state.version(); if *version != new_version { // Observe the new version and return *...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
9cc4a81678ffb423cf89c12b08241272c1b6ecb1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9cc4a81678ffb423cf89c12b08241272c1b6ecb1/tokio/src/sync/watch.rs
881
940
tokio-rs/tokio:tokio/src/sync/watch.rs:24
// loop around again in case the wake-up was spurious } } impl<T> Clone for Receiver<T> { fn clone(&self) -> Self { let version = self.version; let shared = self.shared.clone(); Self::from_shared(version, shared) } } impl<T> Drop for Receiver<T> { fn drop(&mut self) { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
9cc4a81678ffb423cf89c12b08241272c1b6ecb1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9cc4a81678ffb423cf89c12b08241272c1b6ecb1/tokio/src/sync/watch.rs
921
980
tokio-rs/tokio:tokio/src/sync/watch.rs:28
/// /// assert!(!state_rx.has_changed().unwrap()); /// assert!(state_tx.send_if_modified(inc_counter_if_odd)); /// assert!(state_rx.has_changed().unwrap()); /// assert_eq!(state_rx.borrow_and_update().counter, 2); /// /// assert!(!state_rx.has_changed().unwrap()); /// assert!(!state_tx.send_...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
9cc4a81678ffb423cf89c12b08241272c1b6ecb1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9cc4a81678ffb423cf89c12b08241272c1b6ecb1/tokio/src/sync/watch.rs
1,081
1,140
tokio-rs/tokio:tokio/src/sync/watch.rs:29
// Release the write lock. // // Incrementing the version counter while holding the lock ensures // that receivers are able to figure out the version number of the // value they are currently looking at. drop(lock); } self.shared.notify_rx.not...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
9cc4a81678ffb423cf89c12b08241272c1b6ecb1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9cc4a81678ffb423cf89c12b08241272c1b6ecb1/tokio/src/sync/watch.rs
1,121
1,180
tokio-rs/tokio:tokio/src/sync/watch.rs:35
/// Returns `true` if senders belong to the same channel. /// /// # Examples /// /// ``` /// let (tx, rx) = tokio::sync::watch::channel(true); /// let tx2 = tx.clone(); /// assert!(tx.same_channel(&tx2)); /// /// let (tx3, rx3) = tokio::sync::watch::channel(true); /// assert!(!tx...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
9cc4a81678ffb423cf89c12b08241272c1b6ecb1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9cc4a81678ffb423cf89c12b08241272c1b6ecb1/tokio/src/sync/watch.rs
1,361
1,420
tokio-rs/tokio:tokio/src/sync/watch.rs:36
use loom::thread; // test for https://github.com/tokio-rs/tokio/issues/3168 #[test] fn watch_spurious_wakeup() { loom::model(|| { let (send, mut recv) = crate::sync::watch::channel(0i32); send.send(1).unwrap(); let send_thread = thread::spawn(move || { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
9cc4a81678ffb423cf89c12b08241272c1b6ecb1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9cc4a81678ffb423cf89c12b08241272c1b6ecb1/tokio/src/sync/watch.rs
1,401
1,460
tokio-rs/tokio:tokio/src/sync/watch.rs:37
let (send, mut recv) = crate::sync::watch::channel(0i32); assert!(send.borrow().eq(&0)); assert!(recv.borrow().eq(&0)); send.send(1).unwrap(); assert!(send.borrow().eq(&1)); let send_thread = thread::spawn(move || { send.send(2).unwrap(); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
9cc4a81678ffb423cf89c12b08241272c1b6ecb1
github
async-runtime
https://github.com/tokio-rs/tokio/blob/9cc4a81678ffb423cf89c12b08241272c1b6ecb1/tokio/src/sync/watch.rs
1,441
1,477
tokio-rs/tokio:tokio/src/sync/watch.rs:34
/// ``` /// use tokio::sync::watch; /// /// #[tokio::main] /// async fn main() { /// let (tx, rx1) = watch::channel("hello"); /// /// assert_eq!(1, tx.receiver_count()); /// /// let mut _rx2 = rx1.clone(); /// /// assert_eq!(2, tx.receiver_count()); /// } ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c8af499990d739f4e849bf33c1e1fa4b353f5958
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c8af499990d739f4e849bf33c1e1fa4b353f5958/tokio/src/sync/watch.rs
1,321
1,380
tokio-rs/tokio:tokio/src/sync/watch.rs:35
} } } // ===== impl Ref ===== impl<T> ops::Deref for Ref<'_, T> { type Target = T; fn deref(&self) -> &T { self.inner.deref() } } #[cfg(all(test, loom))] mod tests { use futures::future::FutureExt; use loom::thread; // test for https://github.com/tokio-rs/tokio/issues/3168 #...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c8af499990d739f4e849bf33c1e1fa4b353f5958
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c8af499990d739f4e849bf33c1e1fa4b353f5958/tokio/src/sync/watch.rs
1,361
1,420
tokio-rs/tokio:tokio/src/sync/watch.rs:36
send.send(3).unwrap(); let mut recv = recv_thread.join().unwrap(); let send_thread = thread::spawn(move || { send.send(2).unwrap(); }); recv.changed().now_or_never(); send_thread.join().unwrap(); }); } #[test] fn watch_b...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c8af499990d739f4e849bf33c1e1fa4b353f5958
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c8af499990d739f4e849bf33c1e1fa4b353f5958/tokio/src/sync/watch.rs
1,401
1,454
tokio-rs/tokio:tokio/src/sync/watch.rs:37
let recv = recv_thread.join().unwrap(); assert!(recv.borrow().eq(&3)); assert!(send.borrow().eq(&3)); send.send(2).unwrap(); thread::spawn(move || { assert!(recv.borrow().eq(&2)); }); assert!(send.borrow().eq(&2)); }); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
c8af499990d739f4e849bf33c1e1fa4b353f5958
github
async-runtime
https://github.com/tokio-rs/tokio/blob/c8af499990d739f4e849bf33c1e1fa4b353f5958/tokio/src/sync/watch.rs
1,441
1,454
tokio-rs/tokio:tokio/src/sync/watch.rs:3
//! sleep(Duration::from_millis(100)).await; //! tx.send("world")?; //! # Ok(()) //! # } //! ``` //! //! # Closing //! //! [`Sender::is_closed`] and [`Sender::closed`] allow the producer to detect //! when all [`Receiver`] handles have been dropped. This indicates that there //! is no further interest in the values bei...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
81
140
tokio-rs/tokio:tokio/src/sync/watch.rs:4
use std::ops; use std::panic; /// Receives values from the associated [`Sender`](struct@Sender). /// /// Instances are created by the [`channel`](fn@channel) function. /// /// To turn this receiver into a `Stream`, you can use the [`WatchStream`] /// wrapper. /// /// [`WatchStream`]: https://docs.rs/tokio-stream/0.1/t...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
121
180
tokio-rs/tokio:tokio/src/sync/watch.rs:7
} } struct Shared<T> { /// The most recent value. value: RwLock<T>, /// The current version. /// /// The lowest bit represents a "closed" state. The rest of the bits /// represent the current version. state: AtomicState, /// Tracks the number of `Receiver` instances. ref_count_rx:...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
241
300
tokio-rs/tokio:tokio/src/sync/watch.rs:8
use std::error::Error; use std::fmt; /// Error produced when sending a value fails. #[derive(PartialEq, Eq, Clone, Copy)] pub struct SendError<T>(pub T); // ===== impl SendError ===== impl<T> fmt::Debug for SendError<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
281
340
tokio-rs/tokio:tokio/src/sync/watch.rs:9
use super::Notify; use crate::sync::notify::Notified; // To avoid contention on the lock inside the `Notify`, we store multiple // copies of it. Then, we use either circular access or randomness to spread // out threads over different `Notify` objects. // // Some simple benchmarks show that ran...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
321
380
tokio-rs/tokio:tokio/src/sync/watch.rs:10
#[cfg(not(all(not(loom), feature = "sync", any(feature = "rt", feature = "macros"))))] pub(super) fn notified(&self) -> Notified<'_> { let i = self.next.fetch_add(1, std::sync::atomic::Ordering::Relaxed) % 8; self.inner[i].notified() } /// This function implements the ca...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
361
420
tokio-rs/tokio:tokio/src/sync/watch.rs:11
/// and the `Receiver`s use `Acquire` ordering for loading the /// current state. This ensures that written values are seen by /// the `Receiver`s for a proper handover. #[derive(Debug)] pub(super) struct AtomicState(AtomicUsize); impl Version { /// Decrements the version. pub(super...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
401
460
tokio-rs/tokio:tokio/src/sync/watch.rs:13
/// let (tx, mut rx) = watch::channel("hello"); /// /// tokio::spawn(async move { /// // Use the equivalent of a "do-while" loop so the initial value is /// // processed before awaiting the `changed()` future. /// loop { /// println!("{}! ", *rx.borrow_and_update()); /// if rx.changed().awai...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
481
540
tokio-rs/tokio:tokio/src/sync/watch.rs:17
/// Although this method is called `has_changed`, it does not check new /// messages for equality, so this call will return true even if the new /// message is equal to the old message. /// /// Returns an error if the channel has been closed. /// # Examples /// /// ``` /// use tokio::syn...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
641
700
tokio-rs/tokio:tokio/src/sync/watch.rs:21
/// /// // in place of changed we have use `wait_for` /// // which would automatically check the current value /// // and wait for changes until the closure returns true. /// assert!(rx2.wait_for(|val| *val == "goodbye").await.is_ok()); /// assert_eq!(*rx2.borrow(), "goodbye"); ...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
801
860
tokio-rs/tokio:tokio/src/sync/watch.rs:22
if closed { return Err(error::RecvError(())); } // Wait for the value to change. closed = changed_impl(&self.shared, &mut self.version).await.is_err(); } } /// Returns `true` if receivers belong to the same channel. /// /// # Examples ///...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
841
900
tokio-rs/tokio:tokio/src/sync/watch.rs:23
if *version != new_version { // Observe the new version and return *version = new_version; return Some(Ok(())); } if state.is_closed() { // The sender has been dropped. return Some(Err(error::RecvError(()))); } None } async fn changed_impl<T>( shared: &Shar...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
881
940
tokio-rs/tokio:tokio/src/sync/watch.rs:24
Self::from_shared(version, shared) } } impl<T> Drop for Receiver<T> { fn drop(&mut self) { // No synchronization necessary as this is only used as a counter and // not memory access. if 1 == self.shared.ref_count_rx.fetch_sub(1, Relaxed) { // This is the last `Receiver` hand...
rust
rust
rust-source
tokio-rs/tokio
tokio/src/sync/watch.rs
MIT
bd4ccae184b0359cb88f9ebc2ba157867e1eee0e
github
async-runtime
https://github.com/tokio-rs/tokio/blob/bd4ccae184b0359cb88f9ebc2ba157867e1eee0e/tokio/src/sync/watch.rs
921
980