]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/futures-api.rs
1 // aux-build:arc_wake.rs
5 use std
::future
::Future
;
9 atomic
::{self, AtomicUsize}
,
14 use arc_wake
::ArcWake
;
20 impl ArcWake
for Counter
{
21 fn wake(self: Arc
<Self>) {
22 Self::wake_by_ref(&self)
24 fn wake_by_ref(arc_self
: &Arc
<Self>) {
25 arc_self
.wakes
.fetch_add(1, atomic
::Ordering
::SeqCst
);
31 impl Future
for MyFuture
{
33 fn poll(self: Pin
<&mut Self>, cx
: &mut Context
<'_
>) -> Poll
<Self::Output
> {
35 let waker
= cx
.waker();
43 let counter
= Arc
::new(Counter
{
44 wakes
: AtomicUsize
::new(0),
46 let waker
= ArcWake
::into_waker(counter
.clone());
47 assert_eq
!(2, Arc
::strong_count(&counter
));
49 let mut context
= Context
::from_waker(&waker
);
50 assert_eq
!(Poll
::Ready(()), Pin
::new(&mut MyFuture
).poll(&mut context
));
51 assert_eq
!(2, counter
.wakes
.load(atomic
::Ordering
::SeqCst
));
54 assert_eq
!(1, Arc
::strong_count(&counter
));