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

Switch from callbacks to promises for findRoad #2

Merged
merged 2 commits into from Nov 10, 2015
Merged

Switch from callbacks to promises for findRoad #2

merged 2 commits into from Nov 10, 2015

Conversation

@JakeChampion
Copy link

@JakeChampion JakeChampion commented Nov 7, 2015

Callbacks are useful when an async action may fire multiple times, promises are useful when an async action only fires once. They also benefit by not inverting the control, which is what callbacks do.

callbacks are useful when an async action may fire multiple times, promises are useful when an async action only fires once. They also benefit by not inverting the control, which is what callbacks do.
@JakeChampion
Copy link
Author

@JakeChampion JakeChampion commented Nov 7, 2015

This has changed the signature of findRoad, the consumer on this function would have to be updated to consume promises instead of passing a callback.

Loading

@aksiksi
Copy link
Owner

@aksiksi aksiksi commented Nov 8, 2015

Thanks for the changes! I've merged them into the dev branch, but I think I'm handling the returned Promise from findRoad incorrectly. What's confusing is that the first Promise can return either a response object or another Promise. How can that be handled?

Loading

var findRoad = (parsed, db, callback) => {
const resp = newResponse();

const findRoad = ({lat, lng}, db) => {
Copy link
Author

@JakeChampion JakeChampion Nov 8, 2015

Choose a reason for hiding this comment

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

findRoad should only be returning a Promise wrapped Response object. I'll comment on the lines with explanations.

Loading

@JakeChampion
Copy link
Author

@JakeChampion JakeChampion commented Nov 8, 2015

If you haven't used Promises a lot, Nolan Lawson has a written quite a good blog post on the topic, it includes a short quiz :-) - http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html

Loading

@aksiksi aksiksi merged commit e5a69c1 into aksiksi:master Nov 10, 2015
@aksiksi
Copy link
Owner

@aksiksi aksiksi commented Nov 10, 2015

It seems there was a slight error which I fixed in the latest commit. Thanks for your contribution!

By the way, you are not appearing in the Contributors graph because you haven't added the email you used to commit to Github.

Loading

@JakeChampion JakeChampion deleted the patch-1 branch Nov 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants