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

How to avoid a race condition with _streamSubscription?.cancel();? #284

Open
stephane-archer opened this issue Jul 8, 2024 · 0 comments

Comments

@stephane-archer
Copy link

I have a function foo that returns a Stream
I have a function onClick that cancels the previous StreamSubscription, calls foo, and adds a new listener

class bar {
StreamSubscription? _streamSubscription;
    Steam foo () {
     ...
    }
    void onClick () {
        await _streamSubscription?.cancel();
        var stream = foo();
        _streamSubscription = stream.listen((element) { print(element) })
    } 
}

from my understanding because of the await _streamSubscription?.cancel(); the user can run multiple times onClick and create a race condition, not all _streamSubscription is sure to be canceled

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

No branches or pull requests

1 participant