asynchronous
Asynchronous promises in rust using threads
Crate | Travis |
---|---|
#Overview
This library provides an usefull way to invoke functions (clousures) in a Promise Style using separated threads. A Promise is a Struct that represents the return value or the error that the funcion produces.
It also allows the execution of tasks in Parallel or Series in deferred, joining the result in a Promise.
It includes methods to manage Event Loops, where there are tasks that "emit" events in background, and they are collected by a promise.
This project is based on the Q Promise library for Node JS and Async.js
#License
Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.
Examples
This is a simple setup for a promise based execution:
use Promise;
new.success.finally_sync;
Deferred execution:
use ;
let d_a = new;
let p_b = new; // Executed right now
let d1 = new;
let d2 = new;
let d3 = new;
let d4 = new;
let d5 = new;
let promise = vec_to_promise;
// Only d1, d2 and d3 are being executed at this time.
assert_eq!;
promise.success.fail.finally_sync;
Simple event loop:
use EventLoop;
let el = new.finish_in_ms;
el.emit;
el.emit;
// Do something here
el.to_promise.finally_sync;