make-a-promise
v1.0.0
Published
Just a few lines of code that I found myself writing over and over
Downloads
3
Readme
make-a-promise
This is an extremely short bit of code that simply provides an alternative way to create a Promise
object.
// example.js
import { createReadStream } from 'fs';
import { makePromise } from 'make-a-promise';
async function readFromStream(fileName) {
const { promise, resolve, reject } = makePromise();
createReadStream(fileName)
// ... (pipe, handle events, etc.) ...
.on('end', resolve)
.on('error', reject);
return promise;
}