Skip to main content

Module smol_adapter

Module smol_adapter 

Source
Available on crate features std and smol-runtime only.
Expand description

Smol runtime adapters.

This module provides a Pollable wrapper that runs a Future on the smol executor and exposes its completion through the poll-based PK Command interface.

§Example

use pk_command::{PkHashmapMethod, smol_adapter::SmolFuturePollable};

let method_accessor = PkHashmapMethod::new(vec![(
    String::from("ECHOO"),
    Box::new(move |param: Option<Vec<u8>>| {
        SmolFuturePollable::from_future(async move {
            // Note the `async` here    ^^^^^
            Ok(param) // Echo back the input as the result
        })
    }),
)]);

// When using smol, you need to run the code within a smol executor context.
// The async tasks you registered above, when called by the other side,
// will run in the smol executor.

Structs§

SmolFuturePollable
A Pollable adapter that spawns a Future onto the smol executor and exposes its completion through the Pollable interface.