Use promises/thenable
See original GitHub issueIt would be nice if functions which take a callback (connect
, query
, etc.) would return a promise/thenable.
The API would have to change because thenable callbacks only receive a single parameter and errors are sent through reject
.
This would allow the library to work seemless with tools like co
and prepare it for async/await which is coming in ES7.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:17
- Comments:18 (5 by maintainers)
Top Results From Across the Web
Promise.prototype.then() - JavaScript - MDN Web Docs
The then() method of a Promise object takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise....
Read more >Thenables in JavaScript - Mastering JS
A thenable is an object that behaves like a promise for the purposes of chaining and async/await, but is not necessarily a promise....
Read more >What's the difference between a Thenable and a Promise?
Traditionally, the then() method returns a Promise . It takes up to two arguments: callback functions for the success (onFulfilled) and failure (onRejected) ......
Read more >Why we use then() method in JavaScript ? - GeeksforGeeks
The then() method in JavaScript has been defined in the Promise API and is used to deal with asynchronous tasks such as an...
Read more >Promise, Thenable and Cancelable Timers in JavaScript
Counterintuitively, we would have needed to use two await back-to-back like below. const promise = sleep(1000) const timer = await promise // ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
async/await is coming to v8 very soon. The
pg
module should be prepared.Adding support for promises is not feature bloat considering promises are by now a language primitive. Furthermore, adding promise support would not be a breaking change as callbacks could exist simultaneously.
I hope I won’t sound arrogant to suggest that pg-promise concludes this discussion nicely, supporting all promise libraries, with high-level transactions and lots more…
@brianc, @EliSnow … and that it is ok to close the issue 😉