icetea-queue 0.1.5 → 0.1.6

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 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 * e + t;
33
+ let r = this.roomSize * (e + 1) + 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) => {
@@ -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*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)})}}});
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+1)+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)})}}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "icetea-queue",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "A simple queue implementation",
6
6
  "main": "./dist/index.umd.cjs",