Skip to content

Instantly share code, notes, and snippets.

@DoumanAsh
Created April 17, 2019 19:27
Show Gist options
  • Save DoumanAsh/fa5ce392bfc3f4302e1f30cd3ae25345 to your computer and use it in GitHub Desktop.
Save DoumanAsh/fa5ce392bfc3f4302e1f30cd3ae25345 to your computer and use it in GitHub Desktop.
///Trait to bootstrap your futures.
pub trait AutoRuntime: futures::Future {
///Runs futures to completion.
///
///## Note
///
///It must not be used from within async context
#[cfg(not(feature = "multi"))]
fn finish(self) -> Result<Self::Item, Self::Error>;
#[cfg(feature = "multi")]
fn finish(self) -> Result<Self::Item, Self::Error> where Self::Item: Send, Self::Error: Send;
///Spawns futures onto global runtime.
///
///## Note
///
///Can be used in any context, but it requires future that returns nothing
fn spawn(self) where Self: 'static + futures::Future<Item=(), Error=()>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment