Comparing version 4.1.1 to 4.2.0
15
index.js
@@ -5,7 +5,7 @@ var EventEmitter = require('events').EventEmitter | ||
class WattPromise { | ||
class _Promise extends Promise { | ||
constructor () { | ||
// hack to check if the consumer is checking for rejections | ||
super(...arguments) | ||
this.handlingReject = false | ||
this.promise = new Promise(...arguments) | ||
} | ||
@@ -15,3 +15,3 @@ | ||
if (onRejected) this.handlingReject = true | ||
this.promise.then(onFulfilled, onRejected) | ||
super.then(onFulfilled, onRejected) | ||
} | ||
@@ -21,3 +21,3 @@ | ||
if (onRejected) this.handlingReject = true | ||
this.promise.catch(onRejected) | ||
super.catch(onRejected) | ||
} | ||
@@ -107,3 +107,2 @@ } | ||
module.exports.Watt = Watt | ||
module.exports.WattPromise = WattPromise | ||
@@ -122,3 +121,3 @@ Watt.prototype._callCb = function () { | ||
// if no cb is specified, return a Promise instead | ||
this._promise = new WattPromise((resolve, reject) => { | ||
this._promise = new _Promise((resolve, reject) => { | ||
this._cb = (err, res) => { | ||
@@ -162,3 +161,3 @@ if (err) { | ||
} | ||
if (res.value instanceof Promise || res.value instanceof WattPromise) { | ||
if (res.value instanceof Promise) { | ||
res.value.then(this.next.bind(this), this.error.bind(this)) | ||
@@ -215,3 +214,3 @@ } | ||
var syncGroup = this._syncGroup | ||
return new WattPromise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
if (!syncGroup) return resolve(null) | ||
@@ -218,0 +217,0 @@ function onFinish (resolve, reject) { |
{ | ||
"name": "gigawatts", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"description": "Powerful generator control flow (fork of watt)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
24
test.js
var test = require('tap').test | ||
var watt = require('.') | ||
var WattPromise = watt.WattPromise | ||
@@ -72,3 +71,3 @@ test('simple wrap', (t) => { | ||
})() | ||
t.ok(promise instanceof WattPromise, 'watt function returned Promise') | ||
t.ok(promise instanceof Promise, 'watt function returned Promise') | ||
promise.then( | ||
@@ -162,3 +161,3 @@ (res) => { | ||
}, { noCallback: true })(() => t.fail('callback should not have been called')) | ||
t.ok(res instanceof WattPromise, 'watt function returned promise') | ||
t.ok(res instanceof Promise, 'watt function returned promise') | ||
}) | ||
@@ -488,1 +487,20 @@ | ||
}) | ||
test('await rethrow error', (t) => { | ||
t.plan(2) | ||
var a = watt(function * () { | ||
throw new Error('a') | ||
}) | ||
var b = async function () { | ||
try { | ||
await a() | ||
} catch (err) { | ||
t.equal(err.message, 'a', 'catch thrown error') | ||
throw new Error('a and b') | ||
} | ||
} | ||
b().then(t.error, function (err) { | ||
t.equal(err.message, 'a and b', 'catch rethrown error') | ||
}) | ||
}) |
32255
7
691