@firestitch/common 12.4.2 → 12.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1499,28 +1499,47 @@
1499
1499
  })(exports.QueueState || (exports.QueueState = {}));
1500
1500
 
1501
1501
  var Queue = /** @class */ (function () {
1502
- function Queue(_limit) {
1502
+ function Queue(_limit, _targets) {
1503
+ var _this = this;
1503
1504
  if (_limit === void 0) { _limit = Infinity; }
1504
1505
  this._limit = _limit;
1506
+ this._targets = _targets;
1507
+ this._queueStats = {
1508
+ completed: 0,
1509
+ total: 0,
1510
+ errors: [],
1511
+ };
1512
+ this._doneQueueStats = {
1513
+ completed: 0,
1514
+ total: 0,
1515
+ errors: [],
1516
+ };
1517
+ this._completeQueueStats = {
1518
+ completed: 0,
1519
+ total: 0,
1520
+ errors: [],
1521
+ };
1505
1522
  this._done = new rxjs.Subject();
1506
1523
  this._queue = [];
1507
1524
  this._inProgress = [];
1508
- this._total = 0;
1509
- this._completed = 0;
1510
- this._errors = 0;
1511
1525
  this._state = exports.QueueState.Idle;
1512
1526
  this._destroy$ = new rxjs.Subject();
1527
+ if (_targets) {
1528
+ _targets.forEach(function (target) {
1529
+ _this.push(target);
1530
+ });
1531
+ }
1513
1532
  }
1514
1533
  Object.defineProperty(Queue.prototype, "total", {
1515
1534
  get: function () {
1516
- return this._total;
1535
+ return this._queueStats.total;
1517
1536
  },
1518
1537
  enumerable: false,
1519
1538
  configurable: true
1520
1539
  });
1521
1540
  Object.defineProperty(Queue.prototype, "completed", {
1522
1541
  get: function () {
1523
- return this._completed;
1542
+ return this._queueStats.completed;
1524
1543
  },
1525
1544
  enumerable: false,
1526
1545
  configurable: true
@@ -1541,7 +1560,7 @@
1541
1560
  });
1542
1561
  Object.defineProperty(Queue.prototype, "errors", {
1543
1562
  get: function () {
1544
- return this._errors;
1563
+ return this._queueStats.errors;
1545
1564
  },
1546
1565
  enumerable: false,
1547
1566
  configurable: true
@@ -1585,31 +1604,41 @@
1585
1604
  Queue.prototype.setLimit = function (value) {
1586
1605
  this._limit = value;
1587
1606
  };
1607
+ /**
1608
+ * @depreated
1609
+ */
1588
1610
  Queue.prototype.subscribe = function (fun, err, complete) {
1589
- this._done
1590
- .pipe(operators.takeUntil(this._destroy$))
1611
+ this.observe$
1591
1612
  .subscribe(fun, err, complete);
1592
1613
  };
1593
- Queue.prototype.complete = function (fun, err, complete) {
1594
- var _this = this;
1595
- rxjs.Observable.create(function (observer) {
1596
- if (!_this.isProcessing()) {
1597
- observer.next();
1598
- observer.complete();
1599
- return;
1614
+ Object.defineProperty(Queue.prototype, "observe$", {
1615
+ get: function () {
1616
+ return this._done
1617
+ .pipe(operators.takeUntil(this._destroy$));
1618
+ },
1619
+ enumerable: false,
1620
+ configurable: true
1621
+ });
1622
+ Object.defineProperty(Queue.prototype, "complete$", {
1623
+ get: function () {
1624
+ var _this = this;
1625
+ if (!this.isProcessing()) {
1626
+ return rxjs.of({ total: 0, completed: 0, errors: [] });
1600
1627
  }
1601
- _this.subscribe(function () {
1602
- observer.next();
1603
- observer.complete();
1604
- }, function (error) {
1605
- observer.error(error);
1606
- _this.clear();
1607
- });
1608
- }).subscribe(fun, err, complete);
1628
+ return this.observe$
1629
+ .pipe(operators.take(1), operators.map(function () { return (_this._completeQueueStats); }));
1630
+ },
1631
+ enumerable: false,
1632
+ configurable: true
1633
+ });
1634
+ Queue.prototype.complete = function (fun, err, complete) {
1635
+ this.complete$.subscribe(fun, err, complete);
1609
1636
  };
1610
1637
  Queue.prototype.push = function (target, name) {
1611
1638
  var operation = new Operation(target, name);
1612
- this._total++;
1639
+ this._queueStats.total++;
1640
+ this._doneQueueStats.total++;
1641
+ this._completeQueueStats.total++;
1613
1642
  this._state = exports.QueueState.Processing;
1614
1643
  if (this._inProgress.length < this._limit) {
1615
1644
  this._processOperation(operation);
@@ -1621,15 +1650,17 @@
1621
1650
  };
1622
1651
  Queue.prototype.clear = function () {
1623
1652
  this._queue = [];
1624
- this._total = 0;
1625
- this._errors = 0;
1626
- this._completed = 0;
1627
1653
  this._state = exports.QueueState.Idle;
1628
- this._done = new rxjs.Subject();
1654
+ this._queueStats = {
1655
+ total: 0,
1656
+ errors: [],
1657
+ completed: 0,
1658
+ };
1659
+ this._clearDoneQueueStats();
1629
1660
  };
1630
1661
  Queue.prototype.destroy = function () {
1631
- this.clear();
1632
1662
  this._done.complete();
1663
+ this.clear();
1633
1664
  };
1634
1665
  Queue.prototype._processOperation = function (operation) {
1635
1666
  var _this = this;
@@ -1643,21 +1674,25 @@
1643
1674
  error: function (error) {
1644
1675
  var opIndex = _this._inProgress.indexOf(operation);
1645
1676
  _this._inProgress.splice(opIndex, 1);
1646
- _this._errors++;
1677
+ _this._queueStats.errors.push(error);
1678
+ _this._doneQueueStats.errors.push(error);
1679
+ _this._completeQueueStats.errors.push(error);
1647
1680
  operation.ready$.error(error);
1648
1681
  if (_this.empty) {
1649
1682
  _this._state = exports.QueueState.Idle;
1650
- _this._done.error(error);
1651
1683
  }
1652
1684
  },
1653
1685
  complete: function () {
1654
1686
  var opIndex = _this._inProgress.indexOf(operation);
1655
1687
  _this._inProgress.splice(opIndex, 1);
1656
- _this._completed++;
1688
+ _this._queueStats.completed++;
1689
+ _this._doneQueueStats.completed++;
1690
+ _this._completeQueueStats.completed++;
1657
1691
  operation.ready$.complete();
1658
1692
  if (_this.empty) {
1659
1693
  _this._state = exports.QueueState.Idle;
1660
- _this._done.next();
1694
+ _this._done.next(_this._doneQueueStats);
1695
+ _this._clearDoneQueueStats();
1661
1696
  }
1662
1697
  else {
1663
1698
  if (_this._queue.length) {
@@ -1668,6 +1703,13 @@
1668
1703
  }
1669
1704
  });
1670
1705
  };
1706
+ Queue.prototype._clearDoneQueueStats = function () {
1707
+ this._doneQueueStats = {
1708
+ total: 0,
1709
+ errors: [],
1710
+ completed: 0,
1711
+ };
1712
+ };
1671
1713
  return Queue;
1672
1714
  }());
1673
1715