Skip to content

Commit fe6ef9a

Browse files
refactor: enqueue clear idle timeout to micro task queue (#829)
Co-authored-by: Carlos Fuentes <[email protected]>
1 parent d1d8aa5 commit fe6ef9a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/worker_pool/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ export class WorkerInfo extends AsynchronouslyCreatedResource {
6262
if (this.terminating || this.destroyed) return;
6363

6464
this.terminating = true;
65+
this.clearIdleTimeout();
6566
this.worker.terminate();
6667
this.port.close();
67-
this.clearIdleTimeout();
6868
for (const taskInfo of this.taskInfos.values()) {
6969
taskInfo.done(Errors.ThreadTermination());
7070
}
@@ -121,7 +121,6 @@ export class WorkerInfo extends AsynchronouslyCreatedResource {
121121
};
122122

123123
try {
124-
this.clearIdleTimeout();
125124
this.port.postMessage(message, taskInfo.transferList);
126125
} catch (err) {
127126
// This would mostly happen if e.g. message contains unserializable data
@@ -132,6 +131,7 @@ export class WorkerInfo extends AsynchronouslyCreatedResource {
132131

133132
taskInfo.workerInfo = this;
134133
this.taskInfos.set(taskInfo.taskId, taskInfo);
134+
queueMicrotask(() => this.clearIdleTimeout())
135135
this.ref();
136136

137137
// Inform the worker that there are new messages posted, and wake it up

0 commit comments

Comments
 (0)