Crate repeating_future

Source
Expand description

This crate allows you to make any Future to a futures::Stream by yielding the futures’ result when its ready and calling it over and over again to endlessly produce results.

With the default-enabled feature streams this crate provides a handy FutureStream which makes a futures::Stream out of any Future and streams the results of that Future until the underlying future fails. Look at the stream-example to see how easy life can get. Its a sub-50-lines file which completely converts rumqttc to a futures::Stream.

With disabled feature streams it anyhow defines helpers and a final RepeatingFuture that constructs a Future which gets a Future from a function of an object and forwards its result. When the underlying function is Poll::Ready, the function-future is acquired again. It can be used iE for streaming items from an async-function that just delivers one result per call.

This crate was originally made to extend the terrific rumqttc MQTT-client to support futures::Stream. So all examples are made for this for the moment.

Re-exports§

pub use stream::FutureStream;

Modules§

stream
FutureStream makes a futures::Stream out of any Future and streams the futures’ results after each other; endlessly.

Macros§

impl_getter
Returns a GetFutureFunc for the object object with function func. Func can be any async function in object returning a Future. Example: impl_getter!(rumqttc::EventLoop, poll)

Structs§

RepeatingFuture
A Future that is holds an object and an async function-call in that object, which can be polled over and over again.
UnderlyingObjectFuture
It is used internally here, but left pub as maybe somebody could use it in other circumstances. Holds a pinned future of a function from an object and the object itself, guaranteeing by doing so the lifetime of the object and its func-future to co-exist. You need this if you want to poll a Future of a function from a object in an async manner. As we hold the object together with the future of its function in a tuple, the object lives at least as long as the future it returns.

Type Aliases§

GetFutureFunc
Get the future of a function from an object and ecapsulate the object itself with it in a new future. Use impl_getter!-macro for an easy implementation. This has to be done to assure the lifetime of the object and its functions future.