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

Question about cancel_subscriptions #4950

Open
bwilkerson opened this issue Apr 22, 2024 · 3 comments
Open

Question about cancel_subscriptions #4950

bwilkerson opened this issue Apr 22, 2024 · 3 comments
Labels
P3 A lower priority bug or feature request type-question A question about expected behavior or functionality

Comments

@bwilkerson
Copy link
Member

Is it expected that the lint cancel_subscriptions does not generate a diagnostic for the following code

import 'dart:async';

void f(Stream stream) {
  stream.listen((_) {});
}

but will generate a diagnostic for the following code:

import 'dart:async';

void f(Stream stream) {
  var s = stream.listen((_) {});
}

@pq @srawlins

@bwilkerson bwilkerson added the type-question A question about expected behavior or functionality label Apr 22, 2024
@srawlins
Copy link
Member

I think that's intentional. Or a known limitation. In the latter example, we have a variable, such that we can track whether it is canceled. In the former example, we don't, so we throw our hands up. But I could see it being a false negative.

@bwilkerson
Copy link
Member Author

Yeah, if it isn't assigned to a variable, and it isn't passed as an argument to an invocation, then I think we can conclude that it isn't cancelled.

I don't know that I care deeply about it; I was just surprised when I discovered that it didn't get reported. (I was writing an example, and adding the variable creates an unused_local_variable diagnostic, which is unfortunate for my purposes.)

@pq pq added the P3 A lower priority bug or feature request label Apr 23, 2024
@lrhn
Copy link
Member

lrhn commented Apr 23, 2024

If you're not expecting errors, or is using cancelOnError: true, consider using stream.forEach(...) instead.
(Then you'll get yelled at for not handling the returned future, which you probably should, instead of using an onDone handler.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 A lower priority bug or feature request type-question A question about expected behavior or functionality
Projects
None yet
Development

No branches or pull requests

4 participants