pub struct WaitGroup {
pub total: Arc<AtomicU64>,
pub recv: Arc<Receiver<u64>>,
pub send: Arc<Sender<u64>>,
}
Expand description
WaitGroup impl use channel,it’s also both support sync and async how to use?
- on tokio
use dark_std::sync::WaitGroup;
use std::time::Duration;
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let wg = WaitGroup::new();
let wg2 = wg.clone();
tokio::spawn(async move {
sleep(Duration::from_secs(1)).await;
drop(wg2);
});
wg.wait_async().await;
println!("all done");
}
- on thread
use dark_std::sync::WaitGroup;
use std::time::Duration;
use std::thread::sleep;
fn main() {
let wg = WaitGroup::new();
let wg2 = wg.clone();
std::thread::spawn(move ||{
sleep(Duration::from_secs(1));
drop(wg2);
});
wg.wait();
println!("all done");
}
Fields§
§total: Arc<AtomicU64>
§recv: Arc<Receiver<u64>>
§send: Arc<Sender<u64>>
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WaitGroup
impl RefUnwindSafe for WaitGroup
impl Send for WaitGroup
impl Sync for WaitGroup
impl Unpin for WaitGroup
impl UnwindSafe for WaitGroup
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more