Struct changes_stream::ChangesStream
[−]
[src]
pub struct ChangesStream { /* fields omitted */ }
A structure to generate a readable stream on which you can register handlers.
Internally, the ChangesStream
struct holds 3 members:
Member | Type | Notes |
---|---|---|
db |
String |
A url pointing to the data you'd like to stream. |
lp |
tokio_core::reactor::Core |
The event loop |
handlers |
Vec<F> where F: Fn(& hyper::Chunk ) |
A vector of handlers to be called on each Chunk from the Stream on Read |
Methods
impl ChangesStream
[src]
fn new(db: String) -> ChangesStream
Constructs a new ChangesStream
struct
Takes a single argument, db
, which represents the
url of the data you wish to stream.
Every ChangesStream
struct is initialized with
an event loop (tokio_core::reactor::Core
) and an
empty vector of handlers. See above for more details.
For example, to create a new ChangesStream
struct
for the npmjs registry, you would write:
let url = "https://replicate.npmjs.com/_changes".to_string(); let mut changes = ChangesStream::new(url);
fn on<F: Fn(&Chunk) + 'static>(&mut self, handler: F)
Registers a handler. A handler is simply a function you'd like to call on a chunk from the stream at the time the chunk is read.
.on()
takes a single argument, a closure. The
closure you pass should take a single hyper::Chunk
as an argument.
For example, to write the data in a chunk to standard out, you would write:
changes.on(|change| { io::stdout().write_all(&change).unwrap(); });
fn run(self)
Runs the ChangesStream
struct's event loop, lp
.
Call this after you have regsitered all handlers using
on
.
Takes no arguments.
For example:
changes.run();