1.0.1 • Published 8 years ago

ya-promisify v1.0.1

Weekly downloads
14
License
MIT
Repository
github
Last release
8 years ago

ya-promisify

Yet another promisify module. This node module offers a function to easily convert callback based async functions into promises.

Installation

Just add ya-promisify as dependency:

npm install --save ya-promisify

Usage

Usage is quite straighforward:

const promisify = require('ya-promisify'),
      fs = require('fs'),
      //without specify execution context
      stat = promisify(fs.stat),
      //specifying execution context
      readdir = promisify(fs.readdir, fs)

//now, we can use fs.stat with promise API:
stat('some-dir')
    .then( fileStat => fileStat.isDirectory() ? readdir('some-dir') : Promise.reject('Not a dir') )
    .then( files => console.log(`The folder contains the following files: ${files.join(', ')}`))
    .catch( error => console.error('Something is wrong with the path', error) )