qcloud-iotexplorer-common-libs
Advanced tools
Comparing version 0.10.2 to 0.10.3
export * from './SimpleQueue'; | ||
export * from './CancelableQueue'; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib");tslib_1.__exportStar(require("./SimpleQueue"),exports); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib");tslib_1.__exportStar(require("./SimpleQueue"),exports),tslib_1.__exportStar(require("./CancelableQueue"),exports); | ||
//# sourceMappingURL=index.js.map |
@@ -6,10 +6,11 @@ interface Task<T> { | ||
export declare class SimpleQueue<T, V> { | ||
private taskIdCount; | ||
private queue; | ||
private inBusy; | ||
private startExecute; | ||
private readonly handler; | ||
private readonly onTaskSuccess; | ||
private readonly onTaskError; | ||
private readonly autoStart; | ||
protected taskIdCount: number; | ||
protected queue: Array<Task<T>>; | ||
protected inBusy: boolean; | ||
protected startExecute: boolean; | ||
protected runningTask: Task<T> | null; | ||
protected readonly handler: (params: Task<T>) => V | Promise<V>; | ||
protected readonly onTaskSuccess: (params: Task<T>, result?: V) => void | Promise<void>; | ||
protected readonly onTaskError: (err: any, params: Task<T>) => void | Promise<void>; | ||
protected readonly autoStart: boolean; | ||
constructor({ autoStart, handler, onTaskSuccess, onTaskError, }: { | ||
@@ -28,5 +29,5 @@ autoStart?: boolean; | ||
clear(): void; | ||
private _start; | ||
private getTaskId; | ||
protected consumeTask(): Promise<void>; | ||
protected getTaskId(): string; | ||
} | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SimpleQueue=void 0;var tslib_1=require("tslib"),SimpleQueue=function(){function t(t){var e=t.autoStart,s=void 0===e||e,r=t.handler,i=t.onTaskSuccess,u=t.onTaskError;if(this.taskIdCount=0,this.inBusy=!1,this.startExecute=!1,"function"!=typeof r)throw"params handler is not a function";this.autoStart=s,this.handler=r,this.onTaskSuccess=i,this.onTaskError=u,this.queue=[]}return t.prototype.push=function(t){var e=this.getTaskId();return this.queue.push({taskId:e,businessData:t}),this.autoStart&&this.start(),{taskId:e}},t.prototype.start=function(){this.startExecute=!0,this._start()},t.prototype.remove=function(t){var e=this.queue.findIndex((function(e){return e.taskId===t}));-1!==e&&this.queue.splice(e,1)},t.prototype.stop=function(){this.startExecute=!1},t.prototype.clear=function(){this.stop(),this.queue=[]},t.prototype._start=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,e,s;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:if(!this.startExecute||this.inBusy||this.queue.length<=0)return[2];t=this.queue.shift(),this.inBusy=!0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.handler(t)];case 2:e=r.sent();try{"function"==typeof this.onTaskSuccess&&this.onTaskSuccess(t,e)}catch(t){}return[3,4];case 3:s=r.sent(),console.error("simple queue execute handler error",s);try{"function"==typeof this.onTaskError&&this.onTaskError(s,t)}catch(t){}return[3,4];case 4:return this.inBusy=!1,this._start(),[2]}}))}))},t.prototype.getTaskId=function(){return String(++this.taskIdCount)},t}();exports.SimpleQueue=SimpleQueue; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SimpleQueue=void 0;var tslib_1=require("tslib"),SimpleQueue=function(){function t(t){var s=t.autoStart,e=void 0===s||s,r=t.handler,n=t.onTaskSuccess,i=t.onTaskError;if(this.taskIdCount=0,this.inBusy=!1,this.startExecute=!1,this.runningTask=null,"function"!=typeof r)throw"params handler is not a function";this.autoStart=e,this.handler=r,this.onTaskSuccess=n,this.onTaskError=i,this.queue=[]}return t.prototype.push=function(t){var s=this.getTaskId();return this.queue.push({taskId:s,businessData:t}),this.autoStart&&this.start(),{taskId:s}},t.prototype.start=function(){this.startExecute=!0,this.consumeTask()},t.prototype.remove=function(t){var s=this.queue.findIndex((function(s){return s.taskId===t}));-1!==s&&this.queue.splice(s,1)},t.prototype.stop=function(){this.startExecute=!1},t.prototype.clear=function(){this.stop(),this.queue=[]},t.prototype.consumeTask=function(){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,s,e;return tslib_1.__generator(this,(function(r){switch(r.label){case 0:if(!this.startExecute||this.inBusy||this.queue.length<=0)return[2];t=this.queue.shift(),this.inBusy=!0,this.runningTask=t,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.handler(t)];case 2:s=r.sent();try{"function"==typeof this.onTaskSuccess&&this.onTaskSuccess(t,s)}catch(t){}return[3,4];case 3:e=r.sent(),console.error("simple queue execute handler error",e);try{"function"==typeof this.onTaskError&&this.onTaskError(e,t)}catch(t){}return[3,4];case 4:return this.runningTask=null,this.inBusy=!1,this.consumeTask(),[2]}}))}))},t.prototype.getTaskId=function(){return String(++this.taskIdCount)},t}();exports.SimpleQueue=SimpleQueue; | ||
//# sourceMappingURL=SimpleQueue.js.map |
{ | ||
"name": "qcloud-iotexplorer-common-libs", | ||
"version": "0.10.2", | ||
"version": "0.10.3", | ||
"description": "腾讯云IOT前端通用工具库", | ||
@@ -17,3 +17,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"qcloud-iotexplorer-appdev-sdk": "^2.1.2", | ||
"qcloud-iotexplorer-appdev-sdk": "^2.1.3", | ||
"spark-md5": "^3.0.1", | ||
@@ -25,3 +25,3 @@ "tslib": "^2.0.1" | ||
}, | ||
"gitHead": "8a34db41d3159a19f1ef05bcd1748acadc657ebb" | ||
"gitHead": "ef0e77bd73a83705430000eca73494d4d4de41b2" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46235
29
266
6