Welcome to the async world!
Hey! I’m a tiny little npm module - doasync. ~40 lines of code! Don’t ignore me, I’m very helpful! With me you can call any method of your object without a callback and receive a promise! Object is not modified! Cool, ha?
I can promisify functions as well (not only objects) with the help of util.promisify. But first of all, we must give credit to Proxy and ES6 guys... WeakMap has also proved useful.
npm i --save doasync
const fs = ;const doAsync = ; ;
You can even use native
apply to bind some context:
util.promisify() which is under the hood of this module can interact directly with the V8 API, so it doesn't create closures and will be faster than userland implementations.
Memoization is used in the module to prevent functions from being promisified each time (with the use of WeakMaps).
You can use it in async/await of course!
If you need a custom promisify function - use util.promisify.custom