Skip to content

Commit

Permalink
Fixed a bug with generator progress capturing, if onProgress listener…
Browse files Browse the repository at this point in the history
… was attached before the first yield;
  • Loading branch information
DigitalBrainJS committed Apr 13, 2021
1 parent 82aeccd commit 8bb1161
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions lib/c-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -1488,16 +1488,11 @@ class CPromise extends Promise {
return reject(new TypeError('function must a generator'));
}

let isCaptured;
let progress = 0;
let sum = 0;
let weight = 0;
let promise;

scope.on('capture', () => {
isCaptured = true;
});

const setProgress = (value, _scope, data) => {
progress = (value * weight + sum) / (scope.innerWeight() || 1);
if (progress > 1) {
Expand Down Expand Up @@ -1551,7 +1546,7 @@ class CPromise extends Promise {
weight = promise.isChain ? 1 : promise.weight();

setImmediate(() => {
isCaptured && promise.progress((value, scope, data) => {
scope[_shadow].isCaptured && promise.progress((value, scope, data) => {
setProgress(value, scope, data);
});
});
Expand Down

0 comments on commit 8bb1161

Please sign in to comment.