(db, opts, callback)
| 1339 | |
| 1340 | class Changes$1 extends EE { |
| 1341 | constructor(db, opts, callback) { |
| 1342 | super(); |
| 1343 | this.db = db; |
| 1344 | opts = opts ? clone(opts) : {}; |
| 1345 | var complete = opts.complete = once((err, resp) => { |
| 1346 | if (err) { |
| 1347 | if (listenerCount(this, 'error') > 0) { |
| 1348 | this.emit('error', err); |
| 1349 | } |
| 1350 | } else { |
| 1351 | this.emit('complete', resp); |
| 1352 | } |
| 1353 | this.removeAllListeners(); |
| 1354 | db.removeListener('destroyed', onDestroy); |
| 1355 | }); |
| 1356 | if (callback) { |
| 1357 | this.on('complete', function (resp) { |
| 1358 | callback(null, resp); |
| 1359 | }); |
| 1360 | this.on('error', callback); |
| 1361 | } |
| 1362 | const onDestroy = () => { |
| 1363 | this.cancel(); |
| 1364 | }; |
| 1365 | db.once('destroyed', onDestroy); |
| 1366 | |
| 1367 | opts.onChange = (change, pending, lastSeq) => { |
| 1368 | /* istanbul ignore if */ |
| 1369 | if (this.isCancelled) { |
| 1370 | return; |
| 1371 | } |
| 1372 | tryCatchInChangeListener(this, change, pending, lastSeq); |
| 1373 | }; |
| 1374 | |
| 1375 | var promise = new Promise(function (fulfill, reject) { |
| 1376 | opts.complete = function (err, res$$1) { |
| 1377 | if (err) { |
| 1378 | reject(err); |
| 1379 | } else { |
| 1380 | fulfill(res$$1); |
| 1381 | } |
| 1382 | }; |
| 1383 | }); |
| 1384 | this.once('cancel', function () { |
| 1385 | db.removeListener('destroyed', onDestroy); |
| 1386 | opts.complete(null, {status: 'cancelled'}); |
| 1387 | }); |
| 1388 | this.then = promise.then.bind(promise); |
| 1389 | this['catch'] = promise['catch'].bind(promise); |
| 1390 | this.then(function (result) { |
| 1391 | complete(null, result); |
| 1392 | }, complete); |
| 1393 | |
| 1394 | |
| 1395 | |
| 1396 | if (!db.taskqueue.isReady) { |
| 1397 | db.taskqueue.addTask((failed) => { |
| 1398 | if (failed) { |
nothing calls this directly
no test coverage detected