tokio-lock
Access an object from a single Tokio task.
Why?
Tokio futures run in a multi-threaded environment, which makes accessing an object from different futures complicated. In many cases, however, the object is not thread safe, and has to be accessed from a single thread.
As an example, imagine writing HTTP wrapper for an RPC server. Most likely, this has to be done either with a MPSC (multiple producer single consumer) queue and a large enum of possible messages, or with a mutex guarding access to the object.
This library creates a convenient abstraction on top of MPSC, that is managed internally.
Quick example
extern crate futures;
extern crate tokio;
extern crate tokio_lock;
use *;
use ;
use ;
// Create a Lock instance
let mut lock = new;
// Create a future that is going to manage the `TestObject` instance.
// NOTE: Object is consumed in the process.
let manage = lock.manage;
// Borrow an object from `lock` and execute given closure.
let get_field = lock.get.map;
// NOTE: `manage` is a future and has to be run
run;
Using tokio-lock
Please check our documentation for details.