UNPKG

pouchdb-find

Version:
24 lines (20 loc) 555 B
'use strict'; /* * Simple task queue to sequentialize actions. Assumes callbacks will eventually fire (once). */ var Promise = require('./utils').Promise; function TaskQueue() { this.promise = new Promise(function (fulfill) {fulfill(); }); } TaskQueue.prototype.add = function (promiseFactory) { this.promise = this.promise.catch(function () { // just recover }).then(function () { return promiseFactory(); }); return this.promise; }; TaskQueue.prototype.finish = function () { return this.promise; }; module.exports = TaskQueue;