Skip to content

Commit 39204c3

Browse files
authored
fix(shared): prevent race condition in worker loading and fix ensureLoadBeforeProcess logic (#14)
Co-authored-by-agent: Claude Code
1 parent 5cf3ae6 commit 39204c3

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

packages/shared/src/worker/worker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const createTransformersWorker = <
7777

7878
try {
7979
if (!isLoading && !isReady && !worker) {
80+
isLoading = true
8081
worker = getWorker(createOptions)
8182
workerContext = createContext(worker).context
8283

@@ -101,8 +102,8 @@ export const createTransformersWorker = <
101102
}
102103

103104
const ensureLoadBeforeProcess = async (options?: T2 & { loadOptions?: { options?: T2, payload: LoadMessageEvents<any, string> } }) => {
104-
if (options != null && !options?.loadOptions)
105-
await load(options?.loadOptions?.payload, options?.loadOptions?.options)
105+
if (options?.loadOptions)
106+
await load(options.loadOptions.payload, options.loadOptions.options)
106107
}
107108

108109
const process = async <Params, Results>(payload: Params, onResultType: string, options?: T2 & { loadOptions?: { options?: T2, payload: LoadMessageEvents<any, string> } }) => {

0 commit comments

Comments
 (0)