Skip to content

Fixed AsyncTransition #3881

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fixed AsyncTransition #3881

wants to merge 2 commits into from

Conversation

audioXD
Copy link

@audioXD audioXD commented Apr 26, 2025

Describe the bug
The current implementation AsyncTransition::run is not sound.

Leptos Dependencies

reactive_graph = "0.2.0-rc2"

To Reproduce

#[tokio::test]
async fn test_logic() {
    use std::time::Duration;
    use or_poisoned::OrPoisoned as _;
    use reactive_graph::transition::AsyncTransition;

    tokio::join!(
        AsyncTransition::run(move || async move {
            tokio::time::sleep(Duration::from_millis(1)).await;
            tokio::time::sleep(Duration::from_millis(1)).await;
        }),
        AsyncTransition::run(move || async move {
            tokio::time::sleep(Duration::from_millis(2)).await;
            tokio::time::sleep(Duration::from_millis(2)).await;
        }),
    );

    // Made `global_transition()`and `TransitionInner` `#[doc(hidden)]` + `pub` for this to work
    assert!(reactive_graph::transition::global_transition().write().or_poisoned().is_none(), "A MPSC is still registered")
}

Next Steps
[x ] I will make a PR
[ x] I would like to make a PR, but need help getting started
[ x] I want someone else to take the time to fix this
[x ] This is a low priority for me and is just shared for your information

Fixed the current implementations race condition.
```Rust
#[tokio::test]
async fn test_logic() {
    use std::time::Duration;
    use or_poisoned::OrPoisoned as _;
    use reactive_graph::transition::AsyncTransition;

    tokio::join!(
        AsyncTransition::run(move || async move {
            tokio::time::sleep(Duration::from_millis(1)).await;
            tokio::time::sleep(Duration::from_millis(1)).await;
        }),
        AsyncTransition::run(move || async move {
            tokio::time::sleep(Duration::from_millis(2)).await;
            tokio::time::sleep(Duration::from_millis(2)).await;
        }),
    );

    // Made global_transition() and TransitionInner #[doc(hidden)] for this to work
    assert!(reactive_graph::transition::global_transition().write().or_poisoned().is_none(), "A MPSC is still registered")
}
```
@audioXD
Copy link
Author

audioXD commented Apr 26, 2025

I just realized that we could just use a plain Vec instead of mpsc now...

@audioXD
Copy link
Author

audioXD commented Apr 26, 2025

And I now see that there's an issue where it doesn't pierce into a nested spawn(async move {}); The old implementation kinda did that by accident (at least if the spawned task finished before the main future resolved)

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.

1 participant