diff --git a/src/use.ts b/src/use.ts index 341c595..567695d 100644 --- a/src/use.ts +++ b/src/use.ts @@ -42,10 +42,14 @@ export function useWorkerFn( * Invoke this function in the main thread to create proxy functions of all worker functions. * * @param worker - A Worker instance. + * @param options - An object containing options. * @returns Proxy functions. */ export function useWorkerFns>( worker: MsgPort, + options: { + [NAME in keyof FNS]?: UseWorkerFnOpts; + } = {}, ): ProxyFns { const memo = new Map>(); const fns = new Proxy({}, { @@ -56,7 +60,7 @@ export function useWorkerFns>( if (memo.has(name)) { return memo.get(name); } - const fn = useWorkerFn(name, worker); + const fn = useWorkerFn(name, worker, options[name]); memo.set(name, fn); return fn; }, diff --git a/test/fns.test.ts b/test/fns.test.ts index 23b5e1f..bc907b0 100644 --- a/test/fns.test.ts +++ b/test/fns.test.ts @@ -26,7 +26,11 @@ Deno.test("fns", async (t) => { type: "module", }, ); - const { add, fib } = useWorkerFns(worker); + const { add, fib } = useWorkerFns(worker, { + fib: { + transfer: () => [], + }, + }); assertEquals(await add(1, 2), 3); assertEquals(await add(5, 5), 10); assertEquals(await add(10, 20), 30);