icetea-queue 0.1.9 → 0.1.10
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.d.ts +8 -6
- package/dist/index.js +14 -17
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
export declare class Queue<T> implements QueueInterface<T> {
|
|
2
2
|
#private;
|
|
3
3
|
data: T[];
|
|
4
|
+
result: T[];
|
|
4
5
|
roomSize: number;
|
|
5
6
|
queue: T[];
|
|
6
7
|
queueIndex: number[];
|
|
7
8
|
temp: T[][];
|
|
8
9
|
callback: Function | null;
|
|
9
10
|
callbackIsPromise: boolean;
|
|
10
|
-
completed:
|
|
11
|
+
completed: boolean[];
|
|
11
12
|
completedCallback: Function | null;
|
|
12
13
|
constructor(size: number);
|
|
13
14
|
setData(data?: T[]): this;
|
|
14
|
-
setCompleted(): void;
|
|
15
|
+
setCompleted(index: number): void;
|
|
15
16
|
isPromise(callback: Function): boolean;
|
|
16
|
-
setExecutor(executor: Function):
|
|
17
|
-
onCompleted(callback: Function):
|
|
17
|
+
setExecutor(executor: Function): QueueInterface<T>;
|
|
18
|
+
onCompleted(callback: Function): QueueInterface<T>;
|
|
18
19
|
execute(): void;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
declare interface QueueInterface<T> {
|
|
22
23
|
data: T[];
|
|
24
|
+
result: T[];
|
|
23
25
|
roomSize: number;
|
|
24
26
|
queue: T[];
|
|
25
27
|
queueIndex: number[];
|
|
26
28
|
temp: T[][];
|
|
27
29
|
callback: Function | null;
|
|
28
30
|
callbackIsPromise: boolean;
|
|
29
|
-
completed:
|
|
31
|
+
completed: boolean[];
|
|
30
32
|
completedCallback: Function | null;
|
|
31
33
|
setData(data: T[]): void;
|
|
32
|
-
setCompleted(): void;
|
|
34
|
+
setCompleted(index: number): void;
|
|
33
35
|
isPromise(callback: Function): boolean;
|
|
34
36
|
setExecutor(executor: (item: T, data: T[], index: number) => void): void;
|
|
35
37
|
onCompleted(callback: Function): void;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/queue.ts
|
|
2
2
|
var e = class {
|
|
3
3
|
constructor(e) {
|
|
4
|
-
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 =
|
|
4
|
+
this.data = [], this.result = [], 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 = [], this.completedCallback = null;
|
|
5
5
|
}
|
|
6
6
|
setData(e = []) {
|
|
7
7
|
this.data = e;
|
|
@@ -10,19 +10,16 @@ var e = class {
|
|
|
10
10
|
let e = t.splice(0, 1)[0];
|
|
11
11
|
e && this.#t(n++, e);
|
|
12
12
|
}
|
|
13
|
-
return this.queue = this.queue.map((e, t) => this.temp[t]?.[0] ?? null), this;
|
|
13
|
+
return this.queue = this.queue.map((e, t) => this.temp[t]?.[0] ?? null), this.result = Array(this.data.length).fill(null), this.completed = Array(this.data.length).fill(!1), this;
|
|
14
14
|
}
|
|
15
15
|
#e() {
|
|
16
|
-
this.data = [], this.temp = Array(this.roomSize).fill([]), this.queue = Array(this.roomSize).fill(null), this.queueIndex = this.queue.map((e) => 0), this.completed =
|
|
16
|
+
this.data = [], this.temp = Array(this.roomSize).fill([]), this.queue = Array(this.roomSize).fill(null), this.queueIndex = this.queue.map((e) => 0), this.completed = [];
|
|
17
17
|
}
|
|
18
18
|
#t(e, t) {
|
|
19
19
|
this.temp = this.temp.map((n, r) => r === e ? [...n, t] : n);
|
|
20
20
|
}
|
|
21
|
-
setCompleted() {
|
|
22
|
-
this.completed
|
|
23
|
-
status: !0,
|
|
24
|
-
completed: this.completed
|
|
25
|
-
}), this.completed === this.data.length && this.#e();
|
|
21
|
+
setCompleted(e) {
|
|
22
|
+
this.completed[e] = !0, this.completedCallback && this.completed.every((e) => e) && this.completedCallback({ result: this.result }), this.completed.every((e) => e) && this.#e();
|
|
26
23
|
}
|
|
27
24
|
isPromise(e) {
|
|
28
25
|
return e ? e.constructor.name === "AsyncFunction" : !1;
|
|
@@ -30,30 +27,30 @@ var e = class {
|
|
|
30
27
|
#n(e, t) {
|
|
31
28
|
let n = this.temp?.[e]?.[t];
|
|
32
29
|
if (!n) return;
|
|
33
|
-
let r = e + this.roomSize * t;
|
|
30
|
+
let r, i = e + this.roomSize * t;
|
|
34
31
|
this.queueIndex[e] && (this.queueIndex[e] += 1);
|
|
35
|
-
let
|
|
36
|
-
if (this.callbackIsPromise) return this.callback(n, this.data,
|
|
37
|
-
t && (this
|
|
32
|
+
let a = this.temp[e]?.[this.queueIndex?.[e]];
|
|
33
|
+
if (this.callbackIsPromise) return this.callback(n, this.data, i).then((t) => {
|
|
34
|
+
t && (this.#n(e, this.queueIndex[e]), this.result[i] = t, this.setCompleted(i));
|
|
38
35
|
});
|
|
39
|
-
this.callback(n, this.data,
|
|
36
|
+
r = this.callback(n, this.data, i), a && this.#n(e, this.queueIndex[e]), this.result[i] = r, this.setCompleted(i);
|
|
40
37
|
}
|
|
41
38
|
setExecutor(e) {
|
|
42
39
|
if (!e || typeof e != "function") throw Error("executor is not a function");
|
|
43
|
-
this.callback = e, this.callbackIsPromise = this.isPromise(this.callback);
|
|
40
|
+
return this.callback = e, this.callbackIsPromise = this.isPromise(this.callback), this;
|
|
44
41
|
}
|
|
45
42
|
onCompleted(e) {
|
|
46
43
|
if (!e || typeof e != "function") throw Error("On Compeleted is not a function");
|
|
47
|
-
this.completedCallback = e;
|
|
44
|
+
return this.completedCallback = e, this;
|
|
48
45
|
}
|
|
49
46
|
execute() {
|
|
50
47
|
if (!this.callback) throw Error("callback is not set");
|
|
51
48
|
this.data.length !== 0 && this.queue.map((e, t) => {
|
|
52
49
|
let n = e, r = ++this.queueIndex[t], i;
|
|
53
50
|
if (this.callbackIsPromise) return this.callback(n, this.data, t).then((e) => {
|
|
54
|
-
e && (this
|
|
51
|
+
e && (this.#n(t, r), this.result[t] = e, this.setCompleted(t));
|
|
55
52
|
});
|
|
56
|
-
i = this.callback(n, this.data, t),
|
|
53
|
+
i = this.callback(n, this.data, t), i && this.#n(t, r), this.result[t] = i, this.setCompleted(t);
|
|
57
54
|
});
|
|
58
55
|
}
|
|
59
56
|
};
|
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=
|
|
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.result=[],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=[],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.result=Array(this.data.length).fill(null),this.completed=Array(this.data.length).fill(!1),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=[]}#t(e,t){this.temp=this.temp.map((n,r)=>r===e?[...n,t]:n)}setCompleted(e){this.completed[e]=!0,this.completedCallback&&this.completed.every(e=>e)&&this.completedCallback({result:this.result}),this.completed.every(e=>e)&&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,i=e+this.roomSize*t;this.queueIndex[e]&&(this.queueIndex[e]+=1);let a=this.temp[e]?.[this.queueIndex?.[e]];if(this.callbackIsPromise)return this.callback(n,this.data,i).then(t=>{t&&(this.#n(e,this.queueIndex[e]),this.result[i]=t,this.setCompleted(i))});r=this.callback(n,this.data,i),a&&this.#n(e,this.queueIndex[e]),this.result[i]=r,this.setCompleted(i)}setExecutor(e){if(!e||typeof e!=`function`)throw Error(`executor is not a function`);return this.callback=e,this.callbackIsPromise=this.isPromise(this.callback),this}onCompleted(e){if(!e||typeof e!=`function`)throw Error(`On Compeleted is not a function`);return this.completedCallback=e,this}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.#n(t,r),this.result[t]=e,this.setCompleted(t))});i=this.callback(n,this.data,t),i&&this.#n(t,r),this.result[t]=i,this.setCompleted(t)})}}});
|