1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::{
    pin::Pin,
    task::{Context, Poll},
};

use futures_core::ready;
use pin_project_lite::pin_project;

use crate::{
    actor::Actor,
    fut::{ActorFuture, ActorStream},
};

pin_project! {
    /// Future for the [`finish`](super::ActorStreamExt::finish) method.
    #[derive(Debug)]
    #[must_use = "streams do nothing unless polled"]
    pub struct Finish<S> {
        #[pin]
        pub(crate) stream: S
    }
}

impl<S> Finish<S> {
    pub fn new(stream: S) -> Finish<S> {
        Finish { stream }
    }
}

impl<S, A> ActorFuture<A> for Finish<S>
where
    S: ActorStream<A>,
    A: Actor,
{
    type Output = ();

    fn poll(
        mut self: Pin<&mut Self>,
        act: &mut A,
        ctx: &mut A::Context,
        task: &mut Context<'_>,
    ) -> Poll<()> {
        let mut this = self.as_mut().project();
        while ready!(this.stream.as_mut().poll_next(act, ctx, task)).is_some() {}
        Poll::Ready(())
    }
}