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

Updating library for asynchronous support through promises #171

Merged
merged 4 commits into from
Feb 28, 2017

Conversation

ajcrites
Copy link
Collaborator

@ajcrites ajcrites commented Feb 13, 2017

This completes the change for #134. Asynchronous support is no longer backwards compatible, and the return false and callbacks to handlers have been removed. Now, returning Promises from handlers is required for asynchronous support.

pre and post now both also have asynchronous support. The API functions identically as before as long as you use the Promise chain for asynchronicity. response.send and response.fail can force immediate success or failure. .post can still recover failures. The response.send and response.fail methods return promises that must be returned from inside the promise chain in order to continue it.

Also closes #22

@dblock
Copy link
Collaborator

dblock commented Feb 13, 2017

If @mreinstein would like to do a constructive code review here that'd be much appreciated. Removing non-promised versions to simplify the code in the medium term and #22 is what we're trying to accomplish.

@dblock
Copy link
Collaborator

dblock commented Feb 13, 2017

I merged #167, @ajcrites you should rebase this, update READMEs, CHANGELOGs, UPGRADING.

@dblock
Copy link
Collaborator

dblock commented Feb 13, 2017

Also see #173.

@ajcrites ajcrites force-pushed the force-chain-134 branch 3 times, most recently from ad2a1e0 to 5ee51c7 Compare February 14, 2017 15:02
index.js Outdated
if (e.message) {
return response.fail("Unhandled exception: " + e.message + ".", e);
} else {
return response.fail("Unhandled exception.", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

e often contains a string and this should be part of the .fail() call, especially if e is an indexed message (self.messages[e]`).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean something like response.fail("Unhandled exception: " + e, e)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly!

index.js Outdated
})
.catch(function(e) {
if (typeof self.error == "function") {
self.error(e, request, response);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the default behavior should be to resolve by calling response.send() here as the user error handler, app.error() can still explicitly fail if desired.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See comments on #182 -- I can change this to return self.error and update the documentation to say that error can be async.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should next expect the error handler to return anything in release v3. Instead a call to resolve.send() if it has not been already resolved should suffice. I submitted PR #183 to handle.

@ajcrites
Copy link
Collaborator Author

@dblock this is now up-to-date with current changes and makes .error support asynchronously and default to resolving. I think that this will work best, and I tried to document this functionality as well.

Anything else we need to do to proceed with this update? We can work off of a v4 branch and create an rc rather than using master if we want to spend some time with v3.

@dblock
Copy link
Collaborator

dblock commented Feb 17, 2017

Can you take a look at #186 and merge it if it makes sense? I think @tejashah88 is not around. Then make a 3.2.0 release (follow RELEASING) and I will merge this PR right behind it?

@tejashah88
Copy link
Member

@dblock Sorry for slight inactivity. #186 is just merged.

@dblock
Copy link
Collaborator

dblock commented Feb 17, 2017

What are we paying you for @tejashah88 ;)

This required some updates to the core code to make sure the promise chain and corresponding values are always passed appropriately
Also updated library to ignore value returned from handler as this would be considered an exception to response.send
@ajcrites ajcrites force-pushed the force-chain-134 branch 2 times, most recently from 1dea61a to 244cad9 Compare February 28, 2017 17:13
@dblock
Copy link
Collaborator

dblock commented Feb 28, 2017

I'm merging this.

@dblock dblock merged commit 1efe7e8 into master Feb 28, 2017
@dblock dblock deleted the force-chain-134 branch April 15, 2017 20:59
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.

is it possible to do asynchronous things in pre() ?
4 participants