@leaddreamer/inventorylogic 0.0.3-beta.79 → 0.0.3-beta.80
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 +16 -20
- package/business/Utilities/index.js +1 -0
- package/business/Utilities/other.js +1 -3
- package/business/Utilities/promise-queue/index.js +183 -150
- package/business/Utilities/promise-queue/new.js +231 -0
- package/dist/InventoryLogic.0ac93278.js +35 -0
- package/dist/InventoryLogic.0ac93278.js.map +1 -0
- package/dist/InventoryLogic.31f6d549.js +152 -0
- package/dist/InventoryLogic.31f6d549.js.map +1 -0
- package/dist/InventoryLogic.35827495.js +285 -0
- package/dist/InventoryLogic.35827495.js.map +1 -0
- package/dist/InventoryLogic.37dfff3e.js +72 -0
- package/dist/InventoryLogic.37dfff3e.js.map +1 -0
- package/dist/InventoryLogic.4206cb15.js +213 -0
- package/dist/InventoryLogic.4206cb15.js.map +1 -0
- package/dist/InventoryLogic.44193a77.js +35 -0
- package/dist/InventoryLogic.44193a77.js.map +1 -0
- package/dist/InventoryLogic.46ca6768.js +131 -0
- package/dist/InventoryLogic.46ca6768.js.map +1 -0
- package/dist/InventoryLogic.4d012935.js +151 -0
- package/dist/InventoryLogic.4d012935.js.map +1 -0
- package/dist/InventoryLogic.57f24f5f.js +155 -0
- package/dist/InventoryLogic.57f24f5f.js.map +1 -0
- package/dist/InventoryLogic.59be76a4.js +184 -0
- package/dist/InventoryLogic.59be76a4.js.map +1 -0
- package/dist/InventoryLogic.70925a32.js +375 -0
- package/dist/InventoryLogic.70925a32.js.map +1 -0
- package/dist/InventoryLogic.72fcf301.js +6 -0
- package/dist/InventoryLogic.72fcf301.js.map +1 -0
- package/dist/InventoryLogic.7741caec.js +375 -0
- package/dist/InventoryLogic.7741caec.js.map +1 -0
- package/dist/InventoryLogic.78480e5e.js +152 -0
- package/dist/InventoryLogic.78480e5e.js.map +1 -0
- package/dist/InventoryLogic.80d0e568.js +135 -0
- package/dist/InventoryLogic.80d0e568.js.map +1 -0
- package/dist/InventoryLogic.8a273d2e.js +110 -0
- package/dist/InventoryLogic.8a273d2e.js.map +1 -0
- package/dist/InventoryLogic.8addb055.js +202 -0
- package/dist/InventoryLogic.8addb055.js.map +1 -0
- package/dist/InventoryLogic.9dee46ea.js +6 -0
- package/dist/InventoryLogic.9dee46ea.js.map +1 -0
- package/dist/InventoryLogic.b90f66ea.js +124 -0
- package/dist/InventoryLogic.b90f66ea.js.map +1 -0
- package/dist/InventoryLogic.bb447b4c.js +39 -0
- package/dist/InventoryLogic.bb447b4c.js.map +1 -0
- package/dist/InventoryLogic.d27e84a7.js +75 -0
- package/dist/InventoryLogic.d27e84a7.js.map +1 -0
- package/dist/InventoryLogic.d69ad127.js +217 -0
- package/dist/InventoryLogic.d69ad127.js.map +1 -0
- package/dist/InventoryLogic.e03e6b07.js +245 -0
- package/dist/InventoryLogic.e03e6b07.js.map +1 -0
- package/dist/InventoryLogic.f276f76c.js +213 -0
- package/dist/InventoryLogic.f276f76c.js.map +1 -0
- package/dist/InventoryLogic.f4627c8a.js +160 -0
- package/dist/InventoryLogic.f4627c8a.js.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/index.js +1 -2
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -97,21 +97,19 @@ services.
|
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
* [InventoryLogic](#module_InventoryLogic)
|
|
100
|
-
*
|
|
101
|
-
* [
|
|
102
|
-
* _inner_
|
|
103
|
-
* [~FirebaseConfigObject](#module_InventoryLogic..FirebaseConfigObject) : <code>object</code>
|
|
100
|
+
* [module.exports(firebase, config, thisLogger)](#exp_module_InventoryLogic--module.exports) ⇒ <code>Promise.Firebase</code> ⏏
|
|
101
|
+
* [~FirebaseConfigObject](#module_InventoryLogic--module.exports..FirebaseConfigObject) : <code>object</code>
|
|
104
102
|
|
|
105
|
-
<a name="
|
|
103
|
+
<a name="exp_module_InventoryLogic--module.exports"></a>
|
|
106
104
|
|
|
107
|
-
###
|
|
105
|
+
### module.exports(firebase, config, thisLogger) ⇒ <code>Promise.Firebase</code> ⏏
|
|
108
106
|
all-in-one wrapper for a solid subset of CLIENT-SIDE Firebase
|
|
109
107
|
functions, with a consistent interface. There is a parallel set for
|
|
110
108
|
ADMIN-SIDE functions as well.
|
|
111
109
|
Call/initialize with Firebase Configuration settings in an object as
|
|
112
110
|
described below
|
|
113
111
|
|
|
114
|
-
**Kind**:
|
|
112
|
+
**Kind**: Exported function
|
|
115
113
|
|
|
116
114
|
| Param | Type | Description |
|
|
117
115
|
| --- | --- | --- |
|
|
@@ -128,13 +126,13 @@ import FirebaseWrapper from "@leaddreamer/firebase-wrapper";
|
|
|
128
126
|
FirebaseWrapper(config); //see below
|
|
129
127
|
export * from "@leaddreamer/firebase-wrapper";
|
|
130
128
|
```
|
|
131
|
-
<a name="module_InventoryLogic..FirebaseConfigObject"></a>
|
|
129
|
+
<a name="module_InventoryLogic--module.exports..FirebaseConfigObject"></a>
|
|
132
130
|
|
|
133
|
-
|
|
131
|
+
#### module.exports~FirebaseConfigObject : <code>object</code>
|
|
134
132
|
only authDomain, databaseURL and storageBucket are present when
|
|
135
133
|
called from a cloud environment
|
|
136
134
|
|
|
137
|
-
**Kind**: inner typedef of [<code>
|
|
135
|
+
**Kind**: inner typedef of [<code>module.exports</code>](#exp_module_InventoryLogic--module.exports)
|
|
138
136
|
**Properties**
|
|
139
137
|
|
|
140
138
|
| Name | Type | Description |
|
|
@@ -157,21 +155,19 @@ frontEnd and NodeJS BackEnd
|
|
|
157
155
|
|
|
158
156
|
|
|
159
157
|
* [InventoryLogic](#module_InventoryLogic)
|
|
160
|
-
*
|
|
161
|
-
* [
|
|
162
|
-
* _inner_
|
|
163
|
-
* [~FirebaseConfigObject](#module_InventoryLogic..FirebaseConfigObject) : <code>object</code>
|
|
158
|
+
* [module.exports(firebase, config, thisLogger)](#exp_module_InventoryLogic--module.exports) ⇒ <code>Promise.Firebase</code> ⏏
|
|
159
|
+
* [~FirebaseConfigObject](#module_InventoryLogic--module.exports..FirebaseConfigObject) : <code>object</code>
|
|
164
160
|
|
|
165
|
-
<a name="
|
|
161
|
+
<a name="exp_module_InventoryLogic--module.exports"></a>
|
|
166
162
|
|
|
167
|
-
###
|
|
163
|
+
### module.exports(firebase, config, thisLogger) ⇒ <code>Promise.Firebase</code> ⏏
|
|
168
164
|
all-in-one wrapper for a solid subset of CLIENT-SIDE Firebase
|
|
169
165
|
functions, with a consistent interface. There is a parallel set for
|
|
170
166
|
ADMIN-SIDE functions as well.
|
|
171
167
|
Call/initialize with Firebase Configuration settings in an object as
|
|
172
168
|
described below
|
|
173
169
|
|
|
174
|
-
**Kind**:
|
|
170
|
+
**Kind**: Exported function
|
|
175
171
|
|
|
176
172
|
| Param | Type | Description |
|
|
177
173
|
| --- | --- | --- |
|
|
@@ -188,13 +184,13 @@ import FirebaseWrapper from "@leaddreamer/firebase-wrapper";
|
|
|
188
184
|
FirebaseWrapper(config); //see below
|
|
189
185
|
export * from "@leaddreamer/firebase-wrapper";
|
|
190
186
|
```
|
|
191
|
-
<a name="module_InventoryLogic..FirebaseConfigObject"></a>
|
|
187
|
+
<a name="module_InventoryLogic--module.exports..FirebaseConfigObject"></a>
|
|
192
188
|
|
|
193
|
-
|
|
189
|
+
#### module.exports~FirebaseConfigObject : <code>object</code>
|
|
194
190
|
only authDomain, databaseURL and storageBucket are present when
|
|
195
191
|
called from a cloud environment
|
|
196
192
|
|
|
197
|
-
**Kind**: inner typedef of [<code>
|
|
193
|
+
**Kind**: inner typedef of [<code>module.exports</code>](#exp_module_InventoryLogic--module.exports)
|
|
198
194
|
**Properties**
|
|
199
195
|
|
|
200
196
|
| Name | Type | Description |
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module Utilities
|
|
5
5
|
*/
|
|
6
6
|
import dayjs from "dayjs";
|
|
7
|
-
import promisePool from "es6-promise-pool";
|
|
7
|
+
//import promisePool from "es6-promise-pool";
|
|
8
8
|
import isSameOrAfter from "dayjs/plugin/isSameOrAfter.js";
|
|
9
9
|
import isSameOrBefore from "dayjs/plugin/isSameOrBefore.js";
|
|
10
10
|
import {
|
|
@@ -402,5 +402,3 @@ export function makeHexAsNeeded(color) {
|
|
|
402
402
|
if (colours[color.toLowerCase()]) return colours[color.toLowerCase()];
|
|
403
403
|
return color;
|
|
404
404
|
}
|
|
405
|
-
|
|
406
|
-
export * from "./promise-queue/index.js";
|
|
@@ -1,100 +1,132 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typedefs, constants, support functions and database operations related to Promise getQueueSize
|
|
3
|
-
* Thes
|
|
3
|
+
* Thes are useful for scheduling large serial asynchronous operations
|
|
4
4
|
* @module PromiseQueue
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new rate limited queue. The queue is created with stopped state, i.e. you have to call start() to run jobs.
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
10
|
+
export class PromiseQueueClass {
|
|
11
|
+
/**
|
|
12
|
+
* @param {number} maxCallsPerSecond - The rate limit of this queue in maximum calls per seconds which may be executed at any time. Pass values less than 1 to have less than one call per second, e.g. 1/3 for 3 one call in three seconds at maximum.
|
|
13
|
+
* @param {callback} logger optional logger function for errors
|
|
14
|
+
* @constructor
|
|
15
|
+
*/
|
|
16
|
+
constructor(maxCallsPerSecond=1, logger) {
|
|
17
|
+
/**
|
|
18
|
+
* The rate limit of this queue in maximum calls per seconds
|
|
19
|
+
* which may be executed at any time. Pass values less than 1
|
|
20
|
+
* to have less than one call per second, e.g. 1/3 for 3 one
|
|
21
|
+
* call in three seconds at maximum.
|
|
22
|
+
* @type {float}
|
|
23
|
+
*/
|
|
24
|
+
this.maxCallsPerSecond =
|
|
25
|
+
typeof maxCallsPerSecond === "undefined" ? 1 : maxCallsPerSecond;
|
|
26
|
+
/**
|
|
27
|
+
* optional logger function for errors
|
|
28
|
+
* @type {callback}
|
|
29
|
+
*/
|
|
30
|
+
this.logger = logger;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* lists of tasks to be processed, in order, in the queue
|
|
34
|
+
* @type {Array.callback}
|
|
35
|
+
*/
|
|
36
|
+
this.tasks = [];
|
|
37
|
+
/**
|
|
38
|
+
* flag to indicate queue processing is active
|
|
39
|
+
* @type {boolean}
|
|
40
|
+
*/
|
|
41
|
+
this.isActive = false;
|
|
42
|
+
/**
|
|
43
|
+
* pacing for queue processing / rate limiting
|
|
44
|
+
* @type {float}
|
|
45
|
+
*/
|
|
46
|
+
this.jobIntervalMillis = 1000 / maxCallsPerSecond;
|
|
47
|
+
/**
|
|
48
|
+
* timestamp of start of last task
|
|
49
|
+
* @type {time}
|
|
50
|
+
*/
|
|
51
|
+
this.lastTaskTimestamp = null;
|
|
52
|
+
/**
|
|
53
|
+
* @type {string}
|
|
54
|
+
*/
|
|
55
|
+
this.currentTaskTimeoutId = null;
|
|
56
|
+
}
|
|
25
57
|
|
|
26
58
|
/**
|
|
27
59
|
* Processes the next task and returns the id of the time used to wait for the next invocation of this method.
|
|
28
60
|
* @private
|
|
29
61
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
62
|
+
updateTaskSchedule() {
|
|
63
|
+
if (this.logger && this.logger.debug) {
|
|
64
|
+
this.logger.debug("PromiseQueue.updateTaskSchedule");
|
|
65
|
+
}
|
|
34
66
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
67
|
+
if (this.isEmpty() || this.isStopped()) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
38
70
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
const queue = this;
|
|
72
|
+
|
|
73
|
+
function processNextTask() {
|
|
74
|
+
if (queue.logger && queue.logger.debug) {
|
|
75
|
+
queue.logger.debug("PromiseQueue.processNextTask", queue.tasks.length);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var nextTaskItem = queue.tasks.shift();
|
|
79
|
+
if (nextTaskItem) {
|
|
80
|
+
try {
|
|
81
|
+
const result = nextTaskItem.task.call();
|
|
82
|
+
|
|
83
|
+
if (queue.logger && queue.logger.debug) {
|
|
84
|
+
queue.logger.debug(
|
|
85
|
+
"Resolving queued promise",
|
|
86
|
+
result,
|
|
87
|
+
result instanceof Promise
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
nextTaskItem.resolve(result);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
queue.logger.info("rejecting queued promise result", e);
|
|
94
|
+
nextTaskItem.reject(e);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
63
97
|
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
98
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
99
|
+
function scheduleNext(timeoutMillisOverride) {
|
|
100
|
+
if (queue.logger && queue.logger.debug) {
|
|
101
|
+
queue.logger.debug("PromiseQueue.scheduleNext", timeoutMillisOverride);
|
|
102
|
+
}
|
|
71
103
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
104
|
+
if (queue.isEmpty()) {
|
|
105
|
+
queue.currentTaskTimeoutId = null;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
76
108
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
109
|
+
queue.currentTaskTimeoutId = setTimeout(function () {
|
|
110
|
+
queue.lastTaskTimestamp = Date.now();
|
|
111
|
+
processNextTask();
|
|
80
112
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
113
|
+
scheduleNext(queue.jobIntervalMillis);
|
|
114
|
+
}, timeoutMillisOverride);
|
|
115
|
+
}
|
|
84
116
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
117
|
+
if (this.currentTaskTimeoutId == null) {
|
|
118
|
+
if (this.lastTaskTimestamp) {
|
|
119
|
+
let passedTime = Date.now() - this.lastTaskTimestamp;
|
|
120
|
+
if (passedTime > this.jobIntervalMillis) {
|
|
121
|
+
scheduleNext(this.jobIntervalMillis);
|
|
122
|
+
} else {
|
|
123
|
+
scheduleNext(Math.max(0, this.jobIntervalMillis - passedTime));
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
scheduleNext(0);
|
|
127
|
+
}
|
|
92
128
|
}
|
|
93
|
-
|
|
94
|
-
scheduleNext(0);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
129
|
+
};
|
|
98
130
|
|
|
99
131
|
/**
|
|
100
132
|
* Starts the task processing of this queue.
|
|
@@ -104,128 +136,129 @@
|
|
|
104
136
|
*
|
|
105
137
|
* @return {boolean} true if this queue wasn't started before and now started to process tasks.
|
|
106
138
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
139
|
+
start() {
|
|
140
|
+
if (this.isActive) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
111
143
|
|
|
112
|
-
|
|
144
|
+
this.isActive = true;
|
|
113
145
|
|
|
114
|
-
|
|
146
|
+
this.updateTaskSchedule();
|
|
115
147
|
|
|
116
|
-
|
|
117
|
-
|
|
148
|
+
return true;
|
|
149
|
+
};
|
|
118
150
|
|
|
119
151
|
/**
|
|
120
152
|
* Stops the processing of this queue.
|
|
121
153
|
* @return true if the queue was started and is now stopped. false if it was already stopped.
|
|
122
154
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
155
|
+
stop() {
|
|
156
|
+
if (this.isActive) {
|
|
157
|
+
this.isActive = false;
|
|
158
|
+
|
|
159
|
+
if (this.currentTaskTimeoutId) {
|
|
160
|
+
clearInterval(this.currentTaskTimeoutId);
|
|
161
|
+
this.currentTaskTimeoutId = null;
|
|
162
|
+
this.lastTaskTimestamp = null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
134
166
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
167
|
+
getMaxCallsPerSecond() {
|
|
168
|
+
return this.maxCallsPerSecond;
|
|
169
|
+
};
|
|
138
170
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
171
|
+
isStarted() {
|
|
172
|
+
return this.isActive;
|
|
173
|
+
};
|
|
142
174
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
175
|
+
isStopped() {
|
|
176
|
+
return !this.isStarted();
|
|
177
|
+
};
|
|
146
178
|
|
|
147
179
|
/**
|
|
148
180
|
* @returns {boolean} true if this queue is currently empty, i.e. if it has no tasks in the queue.
|
|
149
181
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
182
|
+
isEmpty() {
|
|
183
|
+
return this.tasks.length === 0;
|
|
184
|
+
};
|
|
153
185
|
|
|
154
186
|
/**
|
|
155
187
|
* @returns {boolean} true if this queue has one or more entries.
|
|
156
188
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
189
|
+
isNotEmpty() {
|
|
190
|
+
return !this.isEmpty();
|
|
191
|
+
};
|
|
160
192
|
|
|
161
193
|
/**
|
|
162
194
|
* @param {function} task - The task to add.
|
|
163
195
|
* @param {boolean} append - if the task should be appended or prepended to the list of queued tasks
|
|
164
196
|
* @return {Promise} A promise which is resolved/rejected when the task was executed by the queue.
|
|
165
197
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
198
|
+
async add(task, append) {
|
|
199
|
+
var self = this;
|
|
168
200
|
|
|
169
|
-
|
|
170
|
-
|
|
201
|
+
var promise = new Promise(function (resolve, reject) {
|
|
202
|
+
var newTaskItem = { task: task, resolve: resolve, reject: reject };
|
|
171
203
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
204
|
+
if (self.isEmpty() || append) {
|
|
205
|
+
self.tasks.push(newTaskItem);
|
|
206
|
+
} else {
|
|
207
|
+
self.tasks.unshift(newTaskItem);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
178
210
|
|
|
179
|
-
|
|
211
|
+
self.updateTaskSchedule();
|
|
180
212
|
|
|
181
|
-
|
|
182
|
-
|
|
213
|
+
return promise;
|
|
214
|
+
};
|
|
183
215
|
|
|
184
216
|
/**
|
|
185
217
|
* Appends a new task at the end of the queue.
|
|
186
218
|
* @param {function} task - The task to perform. This function will be called with no arguments.
|
|
187
219
|
* @return {Promise} A promise which is resolved/rejected When the task was executed by the queue
|
|
188
220
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
221
|
+
async append(task) {
|
|
222
|
+
return this.add(task, true);
|
|
223
|
+
};
|
|
192
224
|
|
|
193
225
|
/**
|
|
194
226
|
* Adds a new task as first item in the queue.
|
|
195
227
|
* @param task
|
|
196
228
|
* @return {Promise} A promise which is resolved/rejected When the task was executed by the queue
|
|
197
229
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
230
|
+
async prepend(task) {
|
|
231
|
+
return this.add(task, false);
|
|
232
|
+
};
|
|
201
233
|
|
|
202
234
|
/**
|
|
203
235
|
* Removes the task from the qeueue. If the task is contained more than one time then all occurrences will be removed.
|
|
204
236
|
* @param {function} task - The task to remove.
|
|
205
237
|
* @return {number} - The number of items which were removed.
|
|
206
238
|
*/
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
239
|
+
remove(task) {
|
|
240
|
+
if (this.isEmpty()) {
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
211
243
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
244
|
+
var removedItems = 0;
|
|
245
|
+
for (var i = this.tasks.length - 1; i >= 0; i--) {
|
|
246
|
+
if (this.tasks[i].task === task) {
|
|
247
|
+
this.tasks.splice(i, 1);
|
|
248
|
+
removedItems++;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
219
251
|
|
|
220
|
-
|
|
221
|
-
|
|
252
|
+
return removedItems;
|
|
253
|
+
};
|
|
222
254
|
|
|
223
255
|
/**
|
|
224
256
|
* @returns {Number} - The number of queued/waiting tasks in the queue.
|
|
225
257
|
*/
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
258
|
+
getQueueSize() {
|
|
259
|
+
return this.tasks.length;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
};
|
|
229
263
|
|
|
230
|
-
|
|
231
|
-
})();
|
|
264
|
+
export default PromiseQueue = new PromiseQueueClass(1, null);
|