1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | function base() {
|
8 | return {
|
9 | unreleased: [],
|
10 | push: function push(put) {
|
11 | this.unreleased.push(put);
|
12 | },
|
13 | shift: function shift() {
|
14 | return this.unreleased.shift();
|
15 | },
|
16 | isEmpty: function isEmpty() {
|
17 | return !this.unreleased.length;
|
18 | }
|
19 | };
|
20 | }
|
21 |
|
22 | function fixed(limit, xduce) {
|
23 | return {
|
24 | unreleased: [],
|
25 | released: [],
|
26 | release: function release(put) {
|
27 | this.released.push(put);
|
28 | put.resolve(true);
|
29 | },
|
30 | push: function push(put) {
|
31 | if (this.released.length === limit) {
|
32 | this.unreleased.push(put);
|
33 | } else {
|
34 | this.release(put);
|
35 | }
|
36 | },
|
37 | shift: function shift() {
|
38 | if (!this.released.length) return;
|
39 |
|
40 | var next = this.released.shift();
|
41 |
|
42 | var waiting = this.unreleased.shift();
|
43 | if (waiting) this.release(waiting);
|
44 |
|
45 | return next;
|
46 | },
|
47 | isEmpty: function isEmpty() {
|
48 | return !this.released.length;
|
49 | }
|
50 | };
|
51 | }
|
52 |
|
53 | function dropping(limit) {
|
54 | return {
|
55 | released: [],
|
56 | push: function push(put) {
|
57 | if (this.released.length < limit) {
|
58 | this.released.push(put);
|
59 | }
|
60 | put.resolve(true);
|
61 | },
|
62 | shift: function shift() {
|
63 | return this.released.shift();
|
64 | },
|
65 | isEmpty: function isEmpty() {
|
66 | return !this.released.length;
|
67 | }
|
68 | };
|
69 | }
|
70 |
|
71 | function sliding(limit) {
|
72 | return {
|
73 | released: [],
|
74 | push: function push(put) {
|
75 | if (this.released.length === limit) {
|
76 | this.released = this.released.slice(1).concat([put]);
|
77 | } else {
|
78 | this.released.push(put);
|
79 | }
|
80 | put.resolve(true);
|
81 | },
|
82 | shift: function shift() {
|
83 | return this.released.shift();
|
84 | },
|
85 | isEmpty: function isEmpty() {
|
86 | return !this.released.length;
|
87 | }
|
88 | };
|
89 | }
|
90 |
|
91 | exports.default = { base: base, fixed: fixed, dropping: dropping, sliding: sliding }; |
\ | No newline at end of file |