Browse Source

Don't invoke .ready() callback twice if it throws

Previously, when the callback passed to `.ready()` would throw,
it would be called again because it was also registered as a
`.catch()` handler for the same Promise that invoked it.
master
Anna Henningsen 7 years ago
committed by Mathias Buus
parent
commit
1a59691832
  1. 2
      index.js
  2. 13
      test.js

2
index.js

@ -108,7 +108,7 @@ Blake2b.ready = function (cb) {
rdy = WebAssembly.instantiate(buf).then(setup)
}
return rdy.then(cb).catch(cb)
return rdy.then(cb, cb)
}
function noop () {}

13
test.js

@ -70,3 +70,16 @@ blake2b.ready(function () {
})
})
})
tape('.ready()', function (t) {
var invokeCount = 0;
blake2b
.ready(function () {
invokeCount++
throw new Error()
})
.catch(function () {
t.same(invokeCount, 1)
t.end()
})
});

Loading…
Cancel
Save