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

Sync bound #32

Closed
wants to merge 1 commit into from
Closed

Sync bound #32

wants to merge 1 commit into from

Conversation

planetoryd
Copy link

pub type FutSet<'f> =
    FuturesUnordered<Pin<Box<dyn Future<Output = Result<()>> + marker::Send + Sync + 'f>>>;

assert_impl_all!(FutSet: marker::Send, Sync);

impl Listener {
    // #[async_recursion]
    // async fn sock_accept(sock: UnixListener, set: &FutSet) -> Result<()> {
    //     if let Result::Ok((ux, _anon)) = sock.accept().await {
    //         let fds = ux.recv_stream().await?;
    //         let f: Framed<UnixStream, LengthDelimitedCodec> =
    //             Framed::new(ux, LengthDelimitedCodec::new());
    //         let f = FramedUS(f);
    //         let mut k = Server(f, FDStream(fds));
    //         let id = try_session(
    //             &mut k,
    //             async move |proto: <SubIdentify<'_, Client> as PartialDual<
    //                 '_,
    //                 Client,
    //                 Server,
    //             >>::Dual<End<'_, _>>| { proto.receive().await },
    //         )
    //         .await?;
    //         set.push(Self::sock_accept(sock, set))
    //     }
    //     Ok(())
    // }
    fn sock_accept<'life0, 'async_recursion>(
        sock: UnixListener,
        set: &'life0 FutSet,
    ) -> ::core::pin::Pin<
        Box<dyn ::core::future::Future<Output = Result<()>> + 'async_recursion + ::core::marker::Send + Sync>,
    >
    where
        'life0: 'async_recursion,
    {
        Box::pin(async move {
            if let Result::Ok((ux, _anon)) = sock.accept().await {
                let fds = ux.recv_stream().await?;
                let f: Framed<UnixStream, LengthDelimitedCodec> =
                    Framed::new(ux, LengthDelimitedCodec::new());
                let f = FramedUS(f);
                let mut k = Server(f, FDStream(fds));
                let id = try_session(
                    &mut k,
                    async move |proto: <SubIdentify<'_, Client> as PartialDual<
                        '_,
                        Client,
                        Server,
                    >>::Dual<End<'_, _>>| { proto.receive().await },
                )
                .await?;
                set.push(Self::sock_accept(sock, set))
            }
            Ok(())
        })
    }

I came across the above use case in my project. It requires Sync.

@planetoryd
Copy link
Author

planetoryd commented Sep 29, 2023

Not over yet. In my code I have to remove async-recursion's lifetime bounds to make it work. Maybe I should just give up using macros. oh, I can get around it.

@BigBadE
Copy link

BigBadE commented Mar 11, 2024

+1, I've implemented this myself for async-recursion and async-trait

@dcchut
Copy link
Owner

dcchut commented Mar 17, 2024

Sorry for taking so long to get to this @planetoryd - I've been quite busy.

A few thoughts:

  • Instead of using space as a separator, could you use a comma? e.g. Sync, ?Send and Sync,?Send. (unless there's a technical reason preventing this)
  • Could you add a test where the order of Send + Sync are reversed:
#[async_recursion(Sync, ?Send)]
  • Could you also add some expand tests in tests/expand? These basically test what output the macro is producing - you should be able to see the Sync bound in there.

If you don't particularly feel like working on this let me know and I'll branch off your changes.

@planetoryd
Copy link
Author

I'm busy medmaxxing RN, and it's gonna take a lot of time to familiarize with your project. It's cheaper for both of us if you do it.

@dcchut
Copy link
Owner

dcchut commented Mar 17, 2024

Fixed in #40, released in v1.1.0.

@dcchut dcchut closed this Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants