-
Notifications
You must be signed in to change notification settings - Fork 629
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
Should we be using promises ? #1
Comments
OK, I had a play with what things look like with promises, and it's much nicer. Then I had a play with what things look like using
I've been injecting the fetch function, so that the developer can supply their own fetch polyfill (for browser or node). That feels quite natural. You have inject your API key as well, so the injection step had to happen anyway. Injecting the fetch function will also allow people to unit test against our client library. According to Michael Feathers, this is "the golden rule of API design" (97 Things Every Programmer Should Know, 2010). |
Another issue with Promises and window.fetch(): how do you cancel? This is pretty important for us, since the client library offers to rate-limit and automatically retry.
Since our request function returns a promise, it will have to expose the cancelling mechanism via a revealing constructor. I imagine it looking like this:
Cancelling the request would reject the promise. @juliaogris I'd appreciate your opinion too. |
I ought to mention too that calling cancel() can only be a hint. It doesn't guarantee that the Promise will be rejected. |
Closing this now since I think we've addressed everything here with the current state of the library. |
Promises are the new hotness. They're superior.
And we want our client library to be the new hotness too.
I've just written one test, that uses the client library without promises. 2360d93
It's gross. I really dislike the asymmetry between success (callback) and error (event listener).
Problems:
The text was updated successfully, but these errors were encountered: