Skip to content

Method to turn nodejs style callback functions to promises (so that they can be awaited)

License

Notifications You must be signed in to change notification settings

scriptabuild/awaitable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Method to turn nodejs style callback functions to promises (so that they can be awaited)

Resources

License

Stars

Watchers

Forks

Packages

No packages published