callback-future

Crates.iocallback-future
lib.rscallback-future
version0.1.0
sourcesrc
created_at2020-05-25 15:21:26.922102
updated_at2020-05-25 15:21:26.922102
descriptionAdapter between callbacks and futures
homepage
repositoryhttps://github.com/syrykh/callback-future-rs.git
max_upload_size
id245621
size20,102
Kostiantyn Syrykh (syrykh)

documentation

README

callback-future-rs

A simple adapter between callbacks and futures.

Example

Dependencies:

[dependencies]
callback-future="0.1"

Code:

use callback_future::CallbackFuture;
use futures::executor::block_on;
use std::thread;
use std::time::Duration;

async fn get_result() -> String {
    CallbackFuture::new(
        |complete| {
            // simulate async callback from another thread
            thread::spawn(move || {
                thread::sleep(Duration::from_secs(1));
                complete("Hello, world!".to_string());
            });
        }
    ).await
}

fn main() {
    assert_eq!(block_on(get_result()), "Hello, world!");
}

License

This project is licensed under either of

at your option.

Commit count: 4

cargo fmt