run

Function run 

Source
pub fn run<F, T>(future: F) -> Result<TaskHandler, Error>
where F: Future<Output = T> + Send + 'static, T: Into<TaskResult> + Send + 'static,
Expand description

Runs a given future as a Tokio task while ensuring the main function (marked by #[hermes_five::runtime]) will not finish before all tasks running as done. This is done by using a globally accessible channel to communicate the handlers to be waited by the runtime.

§Parameters

  • future: A future that implements Future<Output = ()>, Send, and has a 'static lifetime.

§Errors

Returns an error if the lock cannot be acquired or if the sender is not initialized or if sending the task handle fails.

§Example

use hermes_five::utils::task;

#[hermes_five::runtime]
async fn main() {
    let handler = task::run(async move {
        // whatever
    }).unwrap();
    // Abort the task early.
    handler.abort();
}