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

In reference to https://github.com/sabre-io/event/pull/66 #67

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

TheTechsTech
Copy link

The issues i'm have when adding some promise tests that works elsewhere.

… why some tests in NotWorkingPromiseTest .php still fails
… general test file for Promise compatibility, mark failing as skipped.
@evert
Copy link
Member

evert commented Dec 10, 2018

Thank you, I'm going to go through these and see what's up!

Copy link
Member

@evert evert left a comment

Choose a reason for hiding this comment

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

In short, i see 1 actionable change here:

  1. Add a resolve and alias + deprecate the fulfill function. I think this is sensible if other projects use the same function name.

The others can be categorized as:

  1. Executor is running synchronously, like JS
  2. Rejecting with non-exceptions
  3. Adding cancel support

I disagree with adding support for 1 & 2. I can see that it might be useful for some to have a default implementation of a CancelablePromise. However, I am curious what your specific use-case for this is? Do you intend to use this library and this is a must-have for you? It's the first time this request was made. I feel that this can be largely implement with just ->reject but maybe I'm missing something important.

{
$finalValue = 0;
$promise = new Promise();
$promise->resolve(1);
Copy link
Member

Choose a reason for hiding this comment

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

I didn't realize, but this first failure is simply because the ->resolve() function doesn't exist. This library uses ->fulfill. I am OK with creating a new function resolve() and make the fulfill() function alias to this. This seems like a good change.

This change should be its own independent pull request. We can mark fulfill() as deprecated and remove it in some future version.

$p->then(null, null)
->then(null, function ($v) use (&$r) { $r = $v; return $v . '2'; })
->then(function ($v) use (&$r2) { $r2 = $v; });
$p->reject('foo');
Copy link
Member

Choose a reason for hiding this comment

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

The second problem is that reject() is called with a string. I don't support this change. Every error should be stay an instance of throwable.

I realize that Javascript does allow rejecting with strings, but in javacript it's also possible to throw 'foo';. I think it's more appropriate for PHP to restrict rejecting strictly with throwable.

public function testThrowsWhenUnwrapIsRejectedWithException()
{
$e = new \Exception('foo');
$p = new Promise(function () use (&$p, $e) { $p->reject($e); });
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's possible for this test to pass. When $p->reject is called, $p doesn't have a value yet. The promise executor should be executed synchronously, just like the Javascript Promise.

Copy link
Member

Choose a reason for hiding this comment

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

There's actually a lot of tests that have this issue.

}

public function testRejectsSelfWhenWaitThrows()
{
Copy link
Member

Choose a reason for hiding this comment

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

I disagree with this test. An exception thrown in the executor function should not result in a rejected promise, it should immediately fail. This is the same as the javascript promise object.

@TheTechsTech
Copy link
Author

However, I am curious what your specific use-case for this is? Do you intend to use this library and this is a must-have for you?

You missed my first reply.

I was checking to find the issues in my own promise library, which i have done. I started here cause ReactPHP have an series of promise tests that all mocks. and your promise implementation operate similar and have real tests and different from Guzzle.

@evert
Copy link
Member

evert commented Dec 10, 2018

Ah I see, that's clear. I think I would say then that adding "cancel" support is probably not something we should do unless there's someone out there that will want to use it ;)

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.

2 participants