-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cleanup worker stuff from memory storage to fix
vitest
(#2004)
Closes #1999
- Loading branch information
1 parent
d0810d3
commit d2e098c
Showing
16 changed files
with
63 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { randomUUID } from 'node:crypto'; | ||
|
||
import { handleMessage } from './fs-utils'; | ||
import type { BackgroundHandlerReceivedMessage } from '../utils'; | ||
|
||
/** | ||
* A map of promises that are created when a background task is scheduled. | ||
* This is used in MemoryStorage#teardown to wait for all tasks to finish executing before exiting the process. | ||
* @internal | ||
*/ | ||
export const promiseMap: Map<string, { | ||
promise: Promise<void>; | ||
resolve: () => void; | ||
}> = new Map(); | ||
|
||
export function scheduleBackgroundTask(message: BackgroundHandlerReceivedMessage) { | ||
const id = randomUUID(); | ||
|
||
let promiseResolve: () => void; | ||
const promise = new Promise<void>((res) => { | ||
promiseResolve = res; | ||
}); | ||
|
||
promiseMap.set(id, { | ||
promise, | ||
resolve: promiseResolve!, | ||
}); | ||
|
||
void handleBackgroundMessage({ | ||
...message, | ||
messageId: id, | ||
}); | ||
} | ||
|
||
async function handleBackgroundMessage(message: BackgroundHandlerReceivedMessage & { messageId: string }) { | ||
await handleMessage(message); | ||
|
||
promiseMap.get(message.messageId)?.resolve(); | ||
promiseMap.delete(message.messageId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
packages/memory-storage/src/workers/file-storage-worker-emulator.ts
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
packages/memory-storage/src/workers/file-storage-worker.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.