feat: account tasks wait time more accurately
[poolifier.git] / src / worker / abstract-worker.ts
index 5d0c9492204e0361b8007ef4dccfb3c0154bebca..176a5893caeeec7cb9d82095840b97498b3822b0 100644 (file)
@@ -207,12 +207,14 @@ export abstract class AbstractWorker<
   ): void {
     try {
       const startTimestamp = performance.now()
+      const waitTime = startTimestamp - (message.submissionTimestamp ?? 0)
       const res = fn(message.data)
       const runTime = performance.now() - startTimestamp
       this.sendToMainWorker({
         data: res,
         id: message.id,
-        runTime
+        runTime,
+        waitTime
       })
     } catch (e) {
       const err = this.handleError(e as Error)
@@ -233,13 +235,15 @@ export abstract class AbstractWorker<
     message: MessageValue<Data>
   ): void {
     const startTimestamp = performance.now()
+    const waitTime = startTimestamp - (message.submissionTimestamp ?? 0)
     fn(message.data)
       .then(res => {
         const runTime = performance.now() - startTimestamp
         this.sendToMainWorker({
           data: res,
           id: message.id,
-          runTime
+          runTime,
+          waitTime
         })
         return null
       })