diff --git a/index.js b/index.js index f797a60..5ef2de3 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const promisify = require('util').promisify +const {promisify} = require('es6-promisify') class PromiseModule { constructor (mod) { @@ -13,9 +13,7 @@ const handler = { if (target.mod[name]) { let val if (typeof target.mod[name] === 'function') { - val = async (...args) => { - return promisify(cb => target.mod[name](...args, cb))() - } + val = (...args) => promisify(cb => target.mod[name](...args, cb))() } else { val = target.mod[name] } diff --git a/package.json b/package.json index adc4b56..a2d145b 100644 --- a/package.json +++ b/package.json @@ -40,5 +40,11 @@ "repository": { "type": "git", "url": "https://github.com/boneskull/promwrap.git" + }, + "dependencies": { + "es6-promisify": "^6.0.0" + }, + "engines": { + "node": ">=6.0.0" } } diff --git a/test/test-basics.js b/test/test-basics.js index fb6e5c3..73abdfc 100644 --- a/test/test-basics.js +++ b/test/test-basics.js @@ -4,13 +4,15 @@ const promwrap = require('../') let fun = (x, cb) => cb(null, x) let _module = {fun, prop: 'test'} -test('test basics', async t => { +test('test basics', t => { t.plan(4) let mod = promwrap(_module) t.same(mod.prop, 'test') t.same(mod.prop, 'test') - t.same(await mod.fun('test1'), 'test1') - t.same(await promwrap(fun)('test2'), 'test2') + return Promise.all([ + mod.fun('test1').then(res => t.same(res, 'test1')), + promwrap(fun)('test2').then(res => t.same(res, 'test2')) + ]) }) test('test error', t => {