pt
promisify-tuple
npm i promisify-tuple
pt

promisify-tuple

Promisify a callback-style function, resolving with [err,val]

by André Staltz

1.2.0 (see all)License:MITTypeScript:Built-In
npm i promisify-tuple
Readme

promisify-tuple

Convert a Node.js-style callback API (err, val) => void to a Promise that resolves to a [err, val] array.

npm install --save promisify-tuple

Before:

const fs = require('fs')

function main() {
  fs.readFile('./test.js', (err, val) => {
    if (err) console.error(err)
    else console.log(val)
  })
}

main()

After:

const fs = require('fs')
const run = require('promisify-tuple')

async function main() {
  const [err, val] = await run(fs.readFile)('./test.js')
  if (err) console.error(err)
  else console.log(val)
}

main()

License

MIT

Downloads/wk

284

GitHub Stars

31

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

2

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
1.2.0
latest
2yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate