Docs.rs
  • context-async-1.0.0
    • context-async 1.0.0
    • Permalink
    • Docs.rs crate page
    • MIT
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • caojen
    • Dependencies
      • actix-web ^4 normal optional
      • async-trait ^0.1 normal
      • log ^0.4 normal
      • rand ^0.8 normal optional
      • tokio ^1 normal
      • tracing ^0.1 normal optional
      • anyhow ^1 dev
      • reqwest ^0.12.9 dev
      • sqlx ^0.8.2 dev
      • tokio ^1 dev
      • tokio-test ^0.4 dev
    • Versions
    • 66.67% of the crate is documented
  • Platform
    • i686-unknown-linux-gnu
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate context_async

context_async1.0.0

  • All Items

Sections

  • Example
  • Error
  • Features

Crate Items

  • Structs
  • Enums
  • Traits
  • Type Aliases
  • Attribute Macros

Crates

  • context_async

Crate context_async

Source
Expand description

This lib provide an trait Context and a Timer to control async function.

§Example

Here is a simple example. We use Timer to control an async function to finish in 5 seconds.

use std::time;
use context_async::{Context, Timer};

async fn a_heavy_async_function(a: u8) -> bool {
    return true;
}

 let timer = Timer::with_timeout(time::Duration::from_secs(5));

 let _ = timer.handle(a_heavy_async_function(0)).await;

 // or:

 use context_async::With;
 let _ = a_heavy_async_function(0).with(&timer).await;

Timer implements Context, you can pass a Context to your async function:


use std::time;
use context_async::{Context, Error, Timer, With};

async fn a_heavy_async_function(a: u8) -> bool {
    return true;
}

async fn my_function<Ctx: Context>(ctx: Ctx) -> Result<bool, Error> {
    a_heavy_async_function(0)
        .with(ctx)
        .await
}

let timer = Timer::with_timeout(time::Duration::from_secs(5));
let _ = my_function(&timer).await;

§Error

Context returns Error, one of Error::ContextCancelled or Error::ContextTimeout.

§Features

  • actix-web-from-request: implement actix-web::FromRequest for Timer.
  • name: create a name for each Context.
  • tracing: enable tracing and do tracing::trace!(...) logging.

Structs§

Namename
Timer
The Timer structure is the default Context.

Enums§

Error

Traits§

Context
The Context trait defines the required methods for Context. It can define a duration, be cancellable, and immediately cancel async functions if the processing time exceeds the allowed duration without being cancelled. Additionally, the Context can spawn child contexts.
With

Type Aliases§

Result

Attribute Macros§

async_trait
Re-export [async_trait] crate.

Results

Settings
Help
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.