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

Better callback as proposed in https://github.com/serverless/examples… #127

Merged
merged 1 commit into from
Apr 3, 2017

Conversation

kaihendry
Copy link
Contributor

Please refer to #125 (comment)

.catch((error) => {
callback(error, null);
});
.then(v => callback(null, v), callback);
Copy link
Contributor

@christophgysin christophgysin Mar 31, 2017

Choose a reason for hiding this comment

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

Thanks! I see now what you were referring to. This guarantees that the callback is not called twice even if it throws an error.

Could you explain the change in the commit message instead of referring to a discussion? Then this is good to go.

…error.

Previously with the .then(v => callback(null, v)).catch(callback), control goes:

1. work
2. callback
3. work (bad: control should never be passed back to the async function after it calls callback)
4. callback (bad: callbacks should never be executed twice)
5. crash

While in this change with .then(v => callback(null, v), callback), control goes:

1. work
2. callback
3. crash

In the second case, control flows correctly and the callback is run only once.
@kaihendry
Copy link
Contributor Author

Commit message updated!

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