question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use promises/thenable

See original GitHub issue

It 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:closed
  • Created 9 years ago
  • Reactions:17
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
calebmercommented, May 26, 2016

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.

1reaction
vitaly-tcommented, May 2, 2016

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 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found