Skip to content

Commit

Permalink
when callback is specified, await for its call (bump version to 1.0.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmdm committed Mar 5, 2019
1 parent b35fe1a commit 30c35ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "promback",
"version": "0.1.5",
"version": "1.0.0",
"description": "Level promises/callbacks landscape",
"main": "promback.js",
"scripts": {
"ci": "npm run lint && npm run cover",
"test": "npm run lint && npm run mocha",
"mocha": "mocha --recursive test",
"test": "mocha --recursive test",
"lint": "eslint promback.js",
"cover": "nyc npm run mocha"
"cover": "nyc npm t"
},
"keywords": [
"promisify",
Expand Down
6 changes: 1 addition & 5 deletions promback.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ function using (PromiseLib) {
return resolve(fn.apply(that, args))
}

const result = fn.call(that, ... args, function (err, value) {
fn.call(that, ... args, function (err, value) {
if (err) { return reject(err) }
resolve(value)
})

if (typeof result !== 'undefined') {
resolve(result)
}
})
}
}
Expand Down
18 changes: 2 additions & 16 deletions test/promback.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ function testUsing (contextTitle, promiseLib) {
assert.deepStrictEqual(result, [ 'a', 10 ])
})

it('resolves when passed function firstly resolves',
async function () {
it('awaits cb if it is specified', async function () {

const fn = promback(function (v, cb) {
setTimeout(function () { cb(null, v) }, 10)
Expand All @@ -122,25 +121,12 @@ function testUsing (contextTitle, promiseLib) {

const result = await fn(7)

assert.deepStrictEqual(result, 14)
})

it('resolves when passed function firstly calls callback',
async function () {

const fn = promback(function (v, cb) {
cb(null, v)
return Promise.resolve(v * 2)
})

const result = await fn(7)

assert.deepStrictEqual(result, 7)
})

it('preserves `this` reference', async function () {

const fn = promback(function (cb) {
const fn = promback(function () {
return this
})

Expand Down

0 comments on commit 30c35ec

Please sign in to comment.