Skip to content

Commit

Permalink
leave note about GC
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkav authored and CurryYangxx committed May 13, 2024
1 parent 99340cc commit 50caca4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/insomnia/src/ui/worker/spectral-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export class SpectralRunner {

public async runDiagnostics({ contents, rulesetPath }: { contents: string; rulesetPath: string }) {
this.taskId = ++this.taskId;
return new Promise<ISpectralDiagnostic[]>((resolve, reject) => {
return new Promise<ISpectralDiagnostic[]>(resolve => {
this.worker.onmessage = (e: MessageEvent<SpectralResponse>) => {
const { id, diagnostics } = e.data;

// onmessage callback will be called several times in one promise,
// and promise can be resolved or rejected only once, so we cant reject it here
// NOTE: we will depend on the garbage collection to clean up the unresolved promises
const hasResultForThisTask = id === this.taskId && diagnostics;
if (hasResultForThisTask) {
resolve(diagnostics);
Expand All @@ -35,7 +36,6 @@ export class SpectralRunner {
} else {
console.error('Error while running diagnostics:', e.data);
}
reject();
};

this.worker.postMessage({
Expand Down

0 comments on commit 50caca4

Please sign in to comment.