Crate transportation[][src]

This crate provides a thin callback wrapper around MIO. For each thread, a thread_local mio::Poll is maintained. This poll can be accessed with borrow_poll. To listen for events on an Evented, do the following:

use transportation::mio;

let token = transportation::insert_listener(|event| println!("Got event: {:?}"));
transportation::borrow_poll(|poll| poll.register(&evented, mio::Token(token), mio::Ready::readable(), mio::PollOpt::level()));


pub extern crate mio;



Run callback with a reference to the internal MIO poll for the current thread. Transportation keeps a separate poll for every thread and it is appropriate to run transportation from multiple threads simultaneously.


Remove an existing interval. Returns true if an interval was removed or false otherwise.


Remove an existing timeout before it has occured. Returns true if a timeout was removed or false otherwise.


Insert a listener and return a unique usize value that can be used to register one or more Eventeds with the internal poll for this thread. Note: this callback will never be called unless borrow_poll(|poll| poll.register()) is called with the returned token.


Remove a previously registered listener. Returns true if a listener was removed and false otherwise. Note: The Evented item must still be removed from the poll separately.


Blocks the thread by polling on the internal MIO poll, dispatching events to event callbacks and calling set_timeout/set_interval callbacks at the appropriate times. Returns when there are no remaining registered time or event callbacks. Panics if called while transportation is already running in this same thread.


Run a callback in a remote thread that is owned by transportation. Spins until the remote thread calls run or run_worker. May deadlock if the remote thread doesn't enter the transportation event loop. May return Err(()) if the remote thread has terminated.


Exactly the same as run, but does not exit when empty. This is useful for threadpool workers (see run_in_thread)


Call callback after interval time has passed, then again once every interval. Returns an identifier that is unique across insert_listener, set_timeout, and set_interval that can be used with the clear_interval function.


Call callback once after timeout has passed. Returns an identifier that is unique across insert_listener, set_timeout, and set_interval that can be used with the clear_timeout function.


Causes the event loop to exit the next time it would iterate. The event loop may be resumed with run() or run_worker()