icetea-queue 0.1.7 → 0.1.9
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 +4 -4
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,11 +52,11 @@ Creates a new queue with the specified number of parallel slots.
|
|
|
52
52
|
Sets the data to be processed and distributes it across the available slots in a round-robin fashion. Returns `this` for chaining.
|
|
53
53
|
|
|
54
54
|
```typescript
|
|
55
|
-
queue.setData([1, 2, 3, 4, 5
|
|
55
|
+
queue.setData([0, 1, 2, 3, 4, 5]);
|
|
56
56
|
// Slot distribution with roomSize=3:
|
|
57
|
-
// Slot 0: [
|
|
58
|
-
// Slot 1: [
|
|
59
|
-
// Slot 2: [
|
|
57
|
+
// Slot 0: [0, 3]
|
|
58
|
+
// Slot 1: [1, 4]
|
|
59
|
+
// Slot 2: [2, 5]
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
#### `setExecutor(executor: Function): void`
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ 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 *
|
|
33
|
+
let r = e + this.roomSize * t;
|
|
34
34
|
this.queueIndex[e] && (this.queueIndex[e] += 1);
|
|
35
35
|
let i = this.temp[e]?.[this.queueIndex?.[e]];
|
|
36
36
|
if (this.callbackIsPromise) return this.callback(n, this.data, r).then((t) => {
|
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++,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*
|
|
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=e+this.roomSize*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)})}}});
|