repeating_future

Crates.iorepeating_future
lib.rsrepeating_future
version0.1.0
sourcesrc
created_at2022-02-21 14:55:39.292279
updated_at2022-02-21 14:55:39.292279
description[RepeatingFuture] is a [Future] that can call an async function of an object over and over again.
homepage
repositoryhttps://github.com/Dirk007/repeating_future
max_upload_size
id536494
size35,068
Dirk Faust (Dirk007)

documentation

README

Crate repeating_future

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.

Usage

Add this crate to your Cargo.toml

repeating_future = "0.1.0"

and use it in your main.rs:

use repeating_future::FutureStream;

Easy example

See Example Or for a manual Stream implementation: Example

Try cargo run --example manual or cargo run --example stream

Commit count: 5

cargo fmt