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.

Constructor promisification

See original GitHub issue

Given this constructor: https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback

new sqlite3.Database(filename, [mode], [callback]) 

where “callback” function will be called when the database was opened successfully or when an error occurred, how can it be promisified? Because this does not works:

(new sqlite3.Database(':memory:', sqlite3.OPEN_READWRITE|sqlite3.OPEN_CREATE)).then(function () {...});

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
petkaantonovcommented, Mar 13, 2015

@benjamingr promisify doesn’t work with constructors

1reaction
benjamingrcommented, Mar 13, 2015

Making constructors perform io operations is a horrible idea o_0

That said - you can convert it to a promise API just like anything else.

In the future - please keep the issue tracker for bugs and feature requests and ask support questions in Stack Overflow - as explained in the contribution guidelines.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promisify imported class (constructor) with bluebird in ES6 + ...
The important part is that the classes' constructor needs to accept a callback as it does database connections and file I/O. If I...
Read more >
How to promisify constructor's handling methods? #558 - GitHub
I'm creating a wrapper to return the "apis" object back to the wrapper's clients. I cannot find a way to use the promises...
Read more >
JavaScript Promisification - W3docs
Promisification is a long term for a straightforward transformation. It represents a conversion of the function, which accepts a callback into a function ......
Read more >
Promise() constructor - JavaScript - MDN Web Docs
The Promise() constructor is primarily used to wrap functions that do not already support promises.
Read more >
Promisification - Bluebird JS
Most libraries can be promisified by requiring the library's classes (constructor functions) and calling promisifyAll on the .prototype .
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