@common.js/yocto-queue 1.1.1 → 1.2.2

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.
package/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  The [yocto-queue](https://www.npmjs.com/package/yocto-queue) package exported as CommonJS modules.
4
4
 
5
- Exported from [yocto-queue@1.1.1](https://www.npmjs.com/package/yocto-queue/v/1.1.1) using https://github.com/etienne-martin/common.js.
5
+ Exported from [yocto-queue@1.2.2](https://www.npmjs.com/package/yocto-queue/v/1.2.2) using https://github.com/etienne-martin/common.js.
package/index.d.ts CHANGED
@@ -33,8 +33,22 @@ export default class Queue<ValueType> implements Iterable<ValueType> {
33
33
  */
34
34
  constructor();
35
35
 
36
+ /**
37
+ The instance is an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), which means you can iterate over the queue front to back with a “for…of” loop. Using the iterator will not remove the items from the queue. If you want that, use `drain()` instead.
38
+
39
+ You can also use spreading to convert the queue to an array. Don't do this unless you really need to though, since it's slow.
40
+ */
36
41
  [Symbol.iterator](): IterableIterator<ValueType>;
37
42
 
43
+ /**
44
+ Returns an iterator that dequeues items as you consume it.
45
+
46
+ This allows you to empty the queue while processing its items.
47
+
48
+ If you want to not remove items as you consume it, use the `Queue` object as an iterator.
49
+ */
50
+ drain(): IterableIterator<ValueType>;
51
+
38
52
  /**
39
53
  Add a value to the queue.
40
54
  */
package/index.js CHANGED
@@ -253,6 +253,10 @@ var Queue = /*#__PURE__*/ function() {
253
253
  }
254
254
  _classPrivateFieldSet(this, _head, _classPrivateFieldGet(this, _head).next);
255
255
  _classPrivateFieldUpdate(this, _size).value--;
256
+ // Clean up tail reference when queue becomes empty
257
+ if (!_classPrivateFieldGet(this, _head)) {
258
+ _classPrivateFieldSet(this, _tail, undefined);
259
+ }
256
260
  return current.value;
257
261
  }
258
262
  },
@@ -313,6 +317,34 @@ var Queue = /*#__PURE__*/ function() {
313
317
  }
314
318
  });
315
319
  }
320
+ },
321
+ {
322
+ key: "drain",
323
+ value: function drain() {
324
+ return __generator(this, function(_state) {
325
+ switch(_state.label){
326
+ case 0:
327
+ if (!_classPrivateFieldGet(this, _head)) return [
328
+ 3,
329
+ 2
330
+ ];
331
+ return [
332
+ 4,
333
+ this.dequeue()
334
+ ];
335
+ case 1:
336
+ _state.sent();
337
+ return [
338
+ 3,
339
+ 0
340
+ ];
341
+ case 2:
342
+ return [
343
+ 2
344
+ ];
345
+ }
346
+ });
347
+ }
316
348
  }
317
349
  ]);
318
350
  return Queue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@common.js/yocto-queue",
3
- "version": "1.1.1",
3
+ "version": "1.2.2",
4
4
  "description": "yocto-queue package exported as CommonJS modules",
5
5
  "license": "MIT",
6
6
  "repository": "etienne-martin/common.js",