We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
It would be useful to have a method on a Future<T> that returns a Future<T?> that resolves to null if it doesn't complete within a timeout.
Future<T>
Future<T?>
This would be useful for cases like _exitCodeOrNull in test_process, which looked like this prior to null safety:
_exitCodeOrNull
Future<int> get _exitCodeOrNull async => await exitCode.timeout(Duration.zero, onTimeout: () => null);
but requires this when migrating to null safety, as exitCode is a Future<int> but we need a Future<int?>:
exitCode
Future<int>
Future<int?>
Future<int?> get _exitCodeOrNull => exitCode .then<int?>((value) => value) .timeout(Duration.zero, onTimeout: () => null);
With an extension method, this could be simplified to:
Future<int?> get _exitCodeOrNull => exitCode.timeoutToNull(Duration.zero);
cc: @nex3
The text was updated successfully, but these errors were encountered:
Note that this is in the same tradition as the collection package's firstWhereOrNull() et al extension methods.
collection
firstWhereOrNull()
Sorry, something went wrong.
It does make sense, yes.
No branches or pull requests
It would be useful to have a method on a
Future<T>
that returns aFuture<T?>
that resolves to null if it doesn't complete within a timeout.This would be useful for cases like
_exitCodeOrNull
in test_process, which looked like this prior to null safety:but requires this when migrating to null safety, as
exitCode
is aFuture<int>
but we need aFuture<int?>
:With an extension method, this could be simplified to:
cc: @nex3
The text was updated successfully, but these errors were encountered: