Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Notify usage with EventIterator #40

Open
AldaronLau opened this issue Dec 19, 2023 · 1 comment
Open

Replace Notify usage with EventIterator #40

AldaronLau opened this issue Dec 19, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@AldaronLau
Copy link
Member

I no longer think the benefits of having Notify as a separate trait are worth the trade-off, since in practice, most Notifys have a point where they could end. Additionally, when using pasts I have found the need for what is essentially a lending async iterator (for updates to the wavy crate - currently wavy uses unsafe code to "get around" this limitation).

Since AsyncIterator is not stable in std yet, this will have to be redefined in pasts, with a compatibility feature that will currently depend on nightly, and one for Stream compatibility.

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=775ff0afbe5e28a0e48403b9145dcef6

pub trait AsyncIterator {
    type Item<'a>;

    fn poll_next<'a>(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item<'a>>>;

    // Return type should be switched out for public type with private constructor
    // 
    // Choosing to take as `Pin` to allow `.next()` to be called in more places,
    // although often more verbose than requiring `Unpin` (may also add `next_unpinned()`)
    fn next<'a>(mut self: Pin<&mut Self>) -> impl Future<Output = Option<Self::Item<'a>>> + '_ {
        std::future::poll_fn(move |cx| self.as_mut().poll_next(cx))
    }
}

Rather than treating an async iterator as a stream, and having another sink type, those concepts build on what an async iterator is (similar to wavy's current design, returning fon's streams and sinks on Ready). I'll add an example later.

@AldaronLau AldaronLau added the enhancement New feature or request label Dec 19, 2023
@AldaronLau AldaronLau added this to the v1.0.0 milestone Dec 19, 2023
@AldaronLau AldaronLau self-assigned this Dec 19, 2023
@AldaronLau
Copy link
Member Author

This is now in the event_iterator crate

@AldaronLau AldaronLau changed the title Replace Notify usage with lending AsyncIterator Replace Notify usage with EventIterator Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant