Closed sivakov512 closed 5 years ago
Good question! Implementing Fibonacci with combinators would look something like:
use futures::Stream;
use tokio::timer::Interval;
use std::time::Duration;
struct Fibonacci {
curr: u64,
next: u64,
}
let mut fib = Fibonacci { curr: 1, next: 1 };
Interval::new_interval(Duration::from_secs(1))
.map(move |_| {
let curr = fib.curr;
let next = curr + fib.next;
fib.curr = fib.next;
fib.next = next;
curr
})
Would you be able to submit a PR to the website adding a fibonnacci section to the combinator page? It doesn't have to be perfect, just get the ball rolling :)
Hi!
Streams page has an example of implementing Fibonacci stream asynchronously by waiting for one second between values ("Getting asynchronous" section), but section "Combinators" has no example of implementing stream with similar wait.
I learn Tokio and am confused about how to implement it. I hope someone will help here with an example and explanation.