@emnapi/core
Advanced tools
@@ -22,2 +22,3 @@ //#region src/emnapi/async-work.js | ||
| pending: [], | ||
| pendingHead: 0, | ||
| init: function () { | ||
@@ -27,6 +28,11 @@ const idGen = { | ||
| list: [], | ||
| listHead: 0, | ||
| generate: function () { | ||
| let id; | ||
| if (idGen.list.length) { | ||
| id = idGen.list.shift(); | ||
| if (idGen.listHead < idGen.list.length) { | ||
| id = idGen.list[idGen.listHead++]; | ||
| if (idGen.listHead === idGen.list.length) { | ||
| idGen.list.length = 0; | ||
| idGen.listHead = 0; | ||
| } | ||
| } | ||
@@ -47,2 +53,3 @@ else { | ||
| emnapiAWST.pending = []; | ||
| emnapiAWST.pendingHead = 0; | ||
| }, | ||
@@ -106,2 +113,6 @@ create: function (env, resource, resourceName, execute, complete, data) { | ||
| if (emnapiAWST.queued.size >= (Math.abs(emnapiAsyncWorkPoolSize) || 4)) { | ||
| if (emnapiAWST.pendingHead >= 1024 && emnapiAWST.pendingHead * 2 >= emnapiAWST.pending.length) { | ||
| emnapiAWST.pending.splice(0, emnapiAWST.pendingHead); | ||
| emnapiAWST.pendingHead = 0; | ||
| } | ||
| emnapiAWST.pending.push(id); | ||
@@ -122,4 +133,8 @@ return; | ||
| }); | ||
| if (emnapiAWST.pending.length > 0) { | ||
| const nextWorkId = emnapiAWST.pending.shift(); | ||
| if (emnapiAWST.pendingHead < emnapiAWST.pending.length) { | ||
| const nextWorkId = emnapiAWST.pending[emnapiAWST.pendingHead++]; | ||
| if (emnapiAWST.pendingHead === emnapiAWST.pending.length) { | ||
| emnapiAWST.pending.length = 0; | ||
| emnapiAWST.pendingHead = 0; | ||
| } | ||
| emnapiAWST.values[nextWorkId].status = 0; | ||
@@ -132,3 +147,3 @@ emnapiAWST.queue(nextWorkId); | ||
| cancel: function (id) { | ||
| const index = emnapiAWST.pending.indexOf(id); | ||
| const index = emnapiAWST.pending.indexOf(id, emnapiAWST.pendingHead); | ||
| if (index !== -1) { | ||
@@ -139,2 +154,6 @@ const work = emnapiAWST.values[id]; | ||
| emnapiAWST.pending.splice(index, 1); | ||
| if (emnapiAWST.pendingHead === emnapiAWST.pending.length) { | ||
| emnapiAWST.pending.length = 0; | ||
| emnapiAWST.pendingHead = 0; | ||
| } | ||
| emnapiCtx.features.setImmediate(() => { | ||
@@ -141,0 +160,0 @@ emnapiAWST.callComplete(work, 11 /* napi_status.napi_cancelled */); |
+1
-1
| { | ||
| "name": "@emnapi/core", | ||
| "version": "2.0.0-alpha.3", | ||
| "version": "2.0.0-alpha.4", | ||
| "description": "emnapi core", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
872580
0.44%19156
0.45%2
100%