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

Enable unawaited_futures, ship fireAndForget #33

Closed
wants to merge 2 commits into from
Closed

Conversation

passsy
Copy link
Owner

@passsy passsy commented Apr 5, 2021

Enables unawaited_futures.

Where Futures are intentionally not awaited, users can disable this lint with fireAndForget which exists as top-level function and extension. It is identical to unawaited from pedantic.

Future<void> logAsync(String msg) async { /*...*/ }

Future<void> someOperation() async {
  await doSomething();

  // Warning: `Future` results in `async` function bodies must be `await`ed or marked `unawaited` using `package:pedantic`.
  logAsync('success');

  // The fireAndForget() extensions signals that await is intentionally missing
  logAsync('success').fireAndForget();

  // The fireAndForget() function signals that await is intentionally missing
  fireAndForget(logAsync('success'));
}

I explicitly did not name it unawaited as it causes naming conflicts. That's the main reason why unawaited was removed from meta again.

Fixes #26

Alternative names

  • notAwaited
  • runInParallel
  • ignoreUnawaitedFuture

@passsy passsy mentioned this pull request Apr 5, 2021
@passsy
Copy link
Owner Author

passsy commented May 21, 2021

I'm not 100% convinced fireAndForget is a good API. The wording should match the error message and should contain "unawaited".

Idea: Force a justification why await wasn't called

  logAsync('success').unawaitedBecause("logging isn't cirical for control flow");
  unawaitedBecause('user does not have to wait for logging', logAsync('success'));

I have to double-check if the string is removed when compiled AOT, since it isn't used.

@passsy
Copy link
Owner Author

passsy commented Aug 16, 2021

Can't land this yet. There is currently a great discussion going on at dart-lang/sdk#46218.

A common method that returns Future but is not awaited is AnimationController.forward(). Let's see how the dart team solves it

@triallax
Copy link

triallax commented May 13, 2022

Just a heads-up: dart:async has had unawaited since Dart 2.15.

@passsy
Copy link
Owner Author

passsy commented Nov 7, 2023

Let's stick with the official unawaited. I still like the idea of unawaitedBecause but it should come from an official Dart package

@passsy passsy closed this Nov 7, 2023
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.

add in unawaited_futures
2 participants