Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Add CancelableOperation.thenOperation #211

Merged
merged 12 commits into from
Apr 18, 2022
Merged

Conversation

natebosch
Copy link
Contributor

@natebosch natebosch commented Mar 18, 2022

Towards dart-lang/core#351

Once combined with Completer.completeOperation this signature adds
significant flexibility for chaining Cancelable work following other
async work.

Move the existing .then implementation to .thenOperation since the latter
is more general.

lrhn and others added 4 commits March 16, 2022 13:40
A prior change made it so that a `.then` on a `CancelableOperation`
would call the `onValue`/`onError` callback even if the
returned operation was cancelled beteen the time of the `then`
and the time the original operation completed.
The result would not show up in the cancelled operation,
but the callbacks would run.

This change blocks calling the callbacks if the returned operation
has been cancelled.
`fail` has a return type of `Never`.
Towards #210

Once combined with `Completer.completeOperation` this signature adds
significant flexibility for chaining Cancelable work following other
async work.

Move the existing `.then` operation to `.thenOperation` since the latter
is more general.
@natebosch natebosch requested a review from lrhn March 18, 2022 02:51
lib/src/cancelable_operation.dart Outdated Show resolved Hide resolved
lib/src/cancelable_operation.dart Outdated Show resolved Hide resolved
lib/src/cancelable_operation.dart Outdated Show resolved Hide resolved
}

/// Creates a new cancelable operation to be completed
/// when this operation completes or is cancelled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a long first paragraph (guildeline is one line).
Not that I can find a good shorter version, though.

lib/src/cancelable_operation.dart Outdated Show resolved Hide resolved
/// when this operation completes or is cancelled.
///
/// The [onValue] and [onError] callbacks behave in the same way as
/// for [Future.then], and the result of those callbacks is used to complete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same way ... well, almost. Future.then is a little clever. If the onError handler throws the same error object that it got in, it considers it a rethrow and uses the old stack instead of the new.
I don't actually think that's valuable here, but maybe change "in the same way as" to "similarly to".

lib/src/cancelable_operation.dart Outdated Show resolved Hide resolved
Base automatically changed from fix-callbacks-after-cancel to master March 18, 2022 23:09
@natebosch natebosch marked this pull request as ready for review April 6, 2022 22:03
@natebosch natebosch merged commit 9e4a6a6 into master Apr 18, 2022
@natebosch natebosch deleted the then-complete-operation branch April 18, 2022 21:52
mosuem pushed a commit to dart-lang/core that referenced this pull request Oct 14, 2024
Towards dart-lang/async#210

Once combined with `Completer.completeOperation` this signature adds
significant flexibility for chaining Cancelable work following other
async work.

Move the existing `.then` implementation to `.thenOperation` since the latter
is more general.

Co-authored-by: Lasse R.H. Nielsen <lrn@google.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants