Skip to content

promisify any error-first async callback operations into promises

Notifications You must be signed in to change notification settings

fengtomy/simplePromisify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

a promisify method used to transform error-first async functions into promised one

such as some methods contained by Node.js fs module, we can promisify these async operations, codes like below:

const fs = require("fs");
const promisify = require("easy-promisify");
const readFilePromise = promisify(fs.readFile, fs); // context is not required, ie fs
readFilePromise("file/path", "utf8")
  .then(file => console.log(file))
  .catch(error => console.log(error));

It also works in browsers and ESM environment.
If you directly link this file in HTML script tag, it will automatically attach to window, window.promisify

About

promisify any error-first async callback operations into promises

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published