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

Add overload of Catch that returns an IPromise or IPromise<PromisedT>… #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ReneB
Copy link

@ReneB ReneB commented May 11, 2020

… to allow asynchronous continuation

These versions of Catch allow for recovery of a chain of promises by
handling an error from an earlier state, then getting back into the
"normal" flow of processing.

Rework of PR #77.

… to allow asynchronous continuation

These versions of Catch allow for recovery of a chain of promises by
handling an error from an earlier state, then getting back into the
"normal" flow of processing.

Rework of PR Real-Serious-Games#77.
@ReneB
Copy link
Author

ReneB commented May 11, 2020

The build passes so there's that.

I've added 4 tests - 2 for the generic Promise class and 2 for the nongeneric version - which test:

  1. continuation (with the value encapsulated in the promise in the generic case) when a resolved promise is passed
  2. rejection when a rejected promise is passed in

In the current version, the code is backwards incompatible for the specific case of Catch blocks that throw and don't return anything, as mentioned in #77 - if you'd prefer a backwards compatible version I will rename the Catch method to something like Recover.

@ReneB
Copy link
Author

ReneB commented May 19, 2020

@RoryDungan could you take a look at this?

recoveryMethod(ex)
.Progress(progress => resultPromise.ReportProgress(progress))
.Then(resolve => resultPromise.Resolve(resolve))
.Catch(reject => resultPromise.Reject(ex));

Choose a reason for hiding this comment

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

resultPromise should be rejected with reject, not ex

onRejected(ex)
.Progress(progress => resultPromise.ReportProgress(progress))
.Then(() => resultPromise.Resolve())
.Catch(reject => resultPromise.Reject(ex));

Choose a reason for hiding this comment

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

resultPromise should be rejected with reject, not ex

promise.Reject(new Exception());

Assert.Equal(expectedValue, actualValue);
}

Choose a reason for hiding this comment

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

You should add some tests to make sure the value passed into onResolved and onRejected are the same as the promise returned in the first catch.

@joeatsalot
Copy link

I support adding this feature. It was one of the big omissions when I used this library. I had to add it in my own fork.

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.

3 participants