Skip to content

async-rs/stop-token

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cooperative cancellation for async-std.

Status: experimental.

See crate docs for details

You can use this crate to create a deadline received through a StopToken:

use async_std::prelude::*; use stop_token::prelude::*; use stop_token::StopToken; struct Event; async fn do_work(work: impl Stream<Item = Event> + Unpin, stop: StopToken) { let mut work = work.until(stop); while let Some(Ok(event)) = work.next().await { process_event(event).await } } async fn process_event(_event: Event) { }

Or Duration or Instant to create a time-based deadline:

use std::time::Instant; use async_std::prelude::*; use stop_token::prelude::*; use stop_token::StopToken; struct Event; async fn do_work(work: impl Stream<Item = Event> + Unpin, until: Instant) { let mut work = work.until(until); while let Some(Ok(event)) = work.next().await { process_event(event).await } } async fn process_event(_event: Event) { }

About

Experimental cooperative cancellation for async-std

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages