Skip to content
This repository was archived by the owner on Jul 29, 2021. It is now read-only.

Commit dbd3591

Browse files
committed
chore: readd pouchdb initialization check
make sure the handler chain is not started, before the corresponding pouchdb instance is fully initialized. Otherwise it might result in a double calling the augmented methods
1 parent 20b1ad7 commit dbd3591

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,28 @@ function callHandlers(handlers, args, method) {
463463
for (var i = handlers.length - 1; i >= 0; i -= 1) {
464464
method = handlers[i].bind(null, method, args);
465465
}
466+
467+
//make sure the handler chain is not started, before the corresponding
468+
//pouchdb instance is fully initialized. Otherwise it might result
469+
//in a double calling the augmented methods
470+
var promise;
471+
if (!args.base.taskqueue.isReady) {
472+
promise = new Promise(function (resolve, reject) {
473+
args.base.taskqueue.addTask(function (failed) {
474+
if (failed) {
475+
reject(failed);
476+
} else {
477+
resolve();
478+
}
479+
});
480+
}).then(function () {
481+
return method();
482+
});
483+
} else {
484+
promise = method();
485+
}
486+
466487
//start running the chain.
467-
var promise = method();
468488
nodify(promise, callback);
469489
return promise;
470490
}

0 commit comments

Comments
 (0)