@scriptabuild/awaitable

1.0.1 • Public • Published

awaitable

Utility to turn a nodejs style asyncronous function (ie. one that takes a function(err, result) callback parameter) into a function that returns a promise instead. (Since such functions can be await'ed.)

Example:

let fileContents = await awaitable(cb => fs.readFile(file, options, cb);

Example creating an async function:

async function readFile(file, options) {
	return awaitable(cb => fs.readFile(file, options, cb));
}

let fileContents = await readFile(file, options);

Example creating an async lambda expression:

let readFile = async(file, options) => awaitable(cb => fs.readFile(file, options, cb);

let fileContents = await readFile(file, options);

Package Sidebar

Install

npm i @scriptabuild/awaitable

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • aeinbu