"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TaskInfo=exports.FixedQueue=exports.ArrayTaskQueue=void 0,exports.isTaskQueue=isTaskQueue;const node_perf_hooks_1=require("node:perf_hooks"),node_async_hooks_1=require("node:async_hooks"),common_1=require("../common"),symbols_1=require("../symbols");var array_queue_1=require("./array_queue");Object.defineProperty(exports,"ArrayTaskQueue",{enumerable:!0,get:function(){return array_queue_1.ArrayTaskQueue}});var fixed_queue_1=require("./fixed_queue");function isTaskQueue(e){return"object"==typeof e&&null!==e&&"size"in e&&"function"==typeof e.shift&&"function"==typeof e.remove&&"function"==typeof e.push}Object.defineProperty(exports,"FixedQueue",{enumerable:!0,get:function(){return fixed_queue_1.FixedQueue}});let taskIdCounter=0;class TaskInfo extends node_async_hooks_1.AsyncResource{constructor(e,s,t,r,i,n,o){super("Piscina.Task",{requireManualDestroy:!0,triggerAsyncId:o}),this.abortListener=null,this.workerInfo=null,this.callback=i,this.task=e,this.transferList=s,(0,common_1.isMovable)(e)&&(null==this.transferList&&(this.transferList=[]),this.transferList=this.transferList.concat(e[symbols_1.kTransferable]),this.task=e[symbols_1.kValue]),this.filename=t,this.name=r,this.taskId=taskIdCounter++,this.abortSignal=n,this.created=node_perf_hooks_1.performance.now(),this.started=0}releaseTask(){const e=this.task;return this.task=null,e}done(e,s){this.runInAsyncScope(this.callback,null,e,s),this.emitDestroy(),this.abortSignal&&this.abortListener&&("removeEventListener"in this.abortSignal&&this.abortListener?this.abortSignal.removeEventListener("abort",this.abortListener):this.abortSignal.off("abort",this.abortListener))}get[symbols_1.kQueueOptions](){return symbols_1.kQueueOptions in this.task?this.task[symbols_1.kQueueOptions]:null}get interface(){return{taskId:this.taskId,filename:this.filename,name:this.name,created:this.created,isAbortable:null!==this.abortSignal,[symbols_1.kQueueOptions]:this[symbols_1.kQueueOptions]}}}exports.TaskInfo=TaskInfo;