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

[RFC] Remove done() method #224

Merged
merged 1 commit into from
Jun 3, 2022
Merged

[RFC] Remove done() method #224

merged 1 commit into from
Jun 3, 2022

Conversation

clue
Copy link
Member

@clue clue commented Jun 2, 2022

This changeset suggests removing the done() method (not to be confused with then() which remains unchanged!). This is done (hah!) in an attempt to reduce the API surface and make the API less confusing and easier to understand. On top of this, this means our APIs are closer to ES6 promises commonly used in JavaScript (see also #219 and #220).

In particular, I consider this method and its relation to the then() method to be somewhat confusing and this has definitely attracted some bad code in the past. Most notably, this method would be used when you would want to ensure a promise is successfully handled in order to make sure we're not hiding any unhandled rejections.

I strongly believe the solution discussed in #87 is superior as it would ensure all unhandled rejections would be reported in the future Promise v3 by default. On top of this, we're transitioning towards using Fibers and coroutines with https://github.com/reactphp/async, so promises would be consumed using await() or yield for many use cases, which would throw any rejections, thus making it less likely to accidentally hide any exceptions.

Given reporting unhandled rejections as discussed in #87 is currently on the foreseeable roadmap, I see little value in having an additional done() method that has the sole purpose of forcefully halting the program in this case. Using an unclean shutdown is not particularly useful in long-running applications and is probably not what we would want to propose as a solution to handle this situation. If a forceful shutdown is desired (making up use cases at this point, but happy to hear about more relevant use cases!), this can still be implemented in userland:

// old
$browser->get($url)->done(function () {
    echo 'Successfully downloaded!';
});

// still supported
$browser->get($url)->then(function () {
    echo 'Successfully downloaded!';
}, function (Exception $e) {
    die 'Error: ' . $e->getMessage() . PHP_EOL;
});

Empirical evidence suggests this interface isn't used much in our ecosystem either, so I'd rather use the chance to clean up our API surface with the upcoming Promise v3 release.

Like #219 and #220, I'm filing this as an RFC to get more feedback on this method and to see how others feel about this. If this gets merged, I'll file a follow-up PR to deprecate this method for Promise v2 to ease upgrading.

@clue clue added the BC break label Jun 2, 2022
@clue clue added this to the v3.0.0 milestone Jun 2, 2022
@clue clue requested review from WyriHaximus and jsor June 2, 2022 11:16
@WyriHaximus
Copy link
Member

@clue This makes sense, but only if we expect #222 to succeed. What are your and @jsor's thoughts on that?

@clue
Copy link
Member Author

clue commented Jun 2, 2022

@clue This makes sense, but only if we expect #222 to succeed. What are your and @jsor's thoughts on that?

@WyriHaximus I'm not sure how #222 is related to #87, but I agree that we should expect unhandled rejections to be reported as discussed in #87. #222 is currently marked as WIP and doesn't contain much information besides the changeset, perhaps this should be addressed/discussed there instead?

I definitely expect #87 to be addressed for Promise v3 and have filed this RFC under this expectation. If this is something we agree on, my vote would be to merge this PR as suggested and address unhandled rejections in the above tickets for Promise v3 👍

@WyriHaximus
Copy link
Member

@clue This makes sense, but only if we expect #222 to succeed. What are your and @jsor's thoughts on that?

@WyriHaximus I'm not sure how #222 is related to #87, but I agree that we should expect unhandled rejections to be reported as discussed in #87. #222 is currently marked as WIP and doesn't contain much information besides the changeset, perhaps this should be addressed/discussed there instead?

@clue #222 is currently marked as WIP because it involves lots of changes and I wanted to have something to show before requesting reviews. But both #222 and #224 have the same goal to resolve #87.

I definitely expect #87 to be addressed for Promise v3 and have filed this RFC under this expectation. If this is something we agree on, my vote would be to merge this PR as suggested and address unhandled rejections in the above tickets for Promise v3 +1

This PR will make #222 a lot easier actually 😉 . So yeah I'm in favor of it.

tests/DeferredTest.php Outdated Show resolved Hide resolved
tests/PromiseTest.php Outdated Show resolved Hide resolved
tests/PromiseTest.php Outdated Show resolved Hide resolved
tests/PromiseTest.php Outdated Show resolved Hide resolved
@WyriHaximus WyriHaximus merged commit 93d4b0f into reactphp:3.x Jun 3, 2022
@clue clue deleted the no-done branch June 3, 2022 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants