icetea-queue 0.1.3 → 0.1.5
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/dist/index.js +8 -7
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var e = class {
|
|
|
8
8
|
let t = Array.from(this.data), n = 0;
|
|
9
9
|
for (; t.length !== 0 && (n === this.temp.length && (n = 0), t.length);) {
|
|
10
10
|
let e = t.splice(0, 1)[0];
|
|
11
|
-
e && this.#t(n
|
|
11
|
+
e && this.#t(n++, e);
|
|
12
12
|
}
|
|
13
13
|
return this.queue = this.queue.map((e, t) => this.temp[t]?.[0] ?? null), this;
|
|
14
14
|
}
|
|
@@ -30,12 +30,13 @@ var e = class {
|
|
|
30
30
|
#n(e, t) {
|
|
31
31
|
let n = this.temp?.[e]?.[t];
|
|
32
32
|
if (!n) return;
|
|
33
|
+
let r = this.roomSize * e + t;
|
|
33
34
|
this.queueIndex[e] && (this.queueIndex[e] += 1);
|
|
34
|
-
let
|
|
35
|
-
if (this.callbackIsPromise) return this.callback(n, this.data,
|
|
35
|
+
let i = this.temp[e]?.[this.queueIndex?.[e]];
|
|
36
|
+
if (this.callbackIsPromise) return this.callback(n, this.data, r).then((t) => {
|
|
36
37
|
t && (this.setCompleted(), this.#n(e, this.queueIndex[e]));
|
|
37
38
|
});
|
|
38
|
-
this.callback(n, this.data,
|
|
39
|
+
this.callback(n, this.data, r), this.setCompleted(), i && this.#n(e, this.queueIndex[e]);
|
|
39
40
|
}
|
|
40
41
|
setExecutor(e) {
|
|
41
42
|
if (!e || typeof e != "function") throw Error("executor is not a function");
|
|
@@ -48,11 +49,11 @@ var e = class {
|
|
|
48
49
|
execute() {
|
|
49
50
|
if (!this.callback) throw Error("callback is not set");
|
|
50
51
|
this.data.length !== 0 && this.queue.map((e, t) => {
|
|
51
|
-
let n = e, r = ++this.queueIndex[t], i
|
|
52
|
-
if (this.callbackIsPromise) return this.callback(n, this.data,
|
|
52
|
+
let n = e, r = ++this.queueIndex[t], i;
|
|
53
|
+
if (this.callbackIsPromise) return this.callback(n, this.data, t).then((e) => {
|
|
53
54
|
e && (this.setCompleted(), this.#n(t, r));
|
|
54
55
|
});
|
|
55
|
-
i = this.callback(n, this.data,
|
|
56
|
+
i = this.callback(n, this.data, t), this.setCompleted(), i && this.#n(t, r);
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`IceTea Queue`]={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),e.Queue=class{constructor(e){this.data=[],this.roomSize=e,this.temp=Array(this.roomSize).fill([]),this.queue=Array(this.roomSize).fill(null),this.queueIndex=this.queue.map(e=>0),this.callback=null,this.callbackIsPromise=!1,this.completed=0,this.completedCallback=null}setData(e=[]){this.data=e;let t=Array.from(this.data),n=0;for(;t.length!==0&&(n===this.temp.length&&(n=0),t.length);){let e=t.splice(0,1)[0];e&&this.#t(n
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`IceTea Queue`]={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),e.Queue=class{constructor(e){this.data=[],this.roomSize=e,this.temp=Array(this.roomSize).fill([]),this.queue=Array(this.roomSize).fill(null),this.queueIndex=this.queue.map(e=>0),this.callback=null,this.callbackIsPromise=!1,this.completed=0,this.completedCallback=null}setData(e=[]){this.data=e;let t=Array.from(this.data),n=0;for(;t.length!==0&&(n===this.temp.length&&(n=0),t.length);){let e=t.splice(0,1)[0];e&&this.#t(n++,e)}return this.queue=this.queue.map((e,t)=>this.temp[t]?.[0]??null),this}#e(){this.data=[],this.temp=Array(this.roomSize).fill([]),this.queue=Array(this.roomSize).fill(null),this.queueIndex=this.queue.map(e=>0),this.completed=0}#t(e,t){this.temp=this.temp.map((n,r)=>r===e?[...n,t]:n)}setCompleted(){this.completed+=1,this.completedCallback&&this.completed===this.data.length&&this.completedCallback({status:!0,completed:this.completed}),this.completed===this.data.length&&this.#e()}isPromise(e){return e?e.constructor.name===`AsyncFunction`:!1}#n(e,t){let n=this.temp?.[e]?.[t];if(!n)return;let r=this.roomSize*e+t;this.queueIndex[e]&&(this.queueIndex[e]+=1);let i=this.temp[e]?.[this.queueIndex?.[e]];if(this.callbackIsPromise)return this.callback(n,this.data,r).then(t=>{t&&(this.setCompleted(),this.#n(e,this.queueIndex[e]))});this.callback(n,this.data,r),this.setCompleted(),i&&this.#n(e,this.queueIndex[e])}setExecutor(e){if(!e||typeof e!=`function`)throw Error(`executor is not a function`);this.callback=e,this.callbackIsPromise=this.isPromise(this.callback)}onCompleted(e){if(!e||typeof e!=`function`)throw Error(`On Compeleted is not a function`);this.completedCallback=e}execute(){if(!this.callback)throw Error(`callback is not set`);this.data.length!==0&&this.queue.map((e,t)=>{let n=e,r=++this.queueIndex[t],i;if(this.callbackIsPromise)return this.callback(n,this.data,t).then(e=>{e&&(this.setCompleted(),this.#n(t,r))});i=this.callback(n,this.data,t),this.setCompleted(),i&&this.#n(t,r)})}}});
|