1.0.1 • Published 7 years ago

@scriptabuild/awaitable v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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);