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

Clean up CancelableOperation. #204

Merged
merged 3 commits into from
Mar 9, 2022
Merged

Clean up CancelableOperation. #204

merged 3 commits into from
Mar 9, 2022

Conversation

lrhn
Copy link
Contributor

@lrhn lrhn commented Mar 4, 2022

Some clean-ups and simplifications of the code.
Should not change any behavior, but differences in future chaining
can potentially change timing.

Some clean-ups and simplifications of the code.
Should not change any behavior, but differences in future chaining
can potentially change timing.
@lrhn lrhn requested a review from natebosch March 4, 2022 15:55
Copy link
Contributor

@natebosch natebosch left a comment

Choose a reason for hiding this comment

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

👍

Looks like a big improvement

@natebosch
Copy link
Contributor

Filed an issue for one of the diagnostics that is showing up: dart-lang/sdk#58677

I'm a little unsure whether the choice to change the cancel return from Future<dynamic> to Future<void> is too breaking to land with the rest. We might want to consider holding that part back until we can dig on whether it will break much existing code.

@lrhn
Copy link
Contributor Author

lrhn commented Mar 7, 2022

I'll roll back the visible type changes, just to be sure.

@lrhn lrhn merged commit d733a5a into master Mar 9, 2022
@natebosch
Copy link
Contributor

This change may have broken some tests. I'm going to dig a bit and see if I can figure out why.

@natebosch
Copy link
Contributor

Here is a small repro case that shows the difference in behavior. This test passes before this PR and fails after.

  test('canceled operation does not call .then callback', () async {
    var completer = Completer<void>();
    var hasInvokedThen = false;
    var operation = CancelableOperation.fromFuture(completer.future).then((_) {
      hasInvokedThen = true;
    });
    operation.cancel();
    completer.complete();
    await pumpEventQueue();
    expect(hasInvokedThen, false);
  });

}
if (!isCanceled) {
value
.then(onValue, onError: onError)
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 what is causing a few tests to fail. Before the onValue would not be called if the returned operation is canceled, but now it only matters whether this operation is canceled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll fix that.

@natebosch natebosch deleted the cleanup-2022 branch March 16, 2022 18:53
mosuem pushed a commit to dart-lang/core that referenced this pull request Oct 14, 2024
* Clean up `CancelableOperation`.

Some clean-ups and simplifications of the code.
Should not change any behavior, but differences in future chaining
can potentially change timing.

But don't change `Future` to `Future<void>` today.
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