File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -42,10 +42,14 @@ export function useWorkerFn<FN extends AnyFn>(
4242 * Invoke this function in the main thread to create proxy functions of all worker functions.
4343 *
4444 * @param worker - A Worker instance.
45+ * @param options - An object containing options.
4546 * @returns Proxy functions.
4647 */
4748export function useWorkerFns < FNS extends Record < string , AnyFn > > (
4849 worker : MsgPort ,
50+ options : {
51+ [ NAME in keyof FNS ] ?: UseWorkerFnOpts < FNS [ NAME ] > ;
52+ } = { } ,
4953) : ProxyFns < FNS > {
5054 const memo = new Map < string , ProxyFn < AnyFn > > ( ) ;
5155 const fns = new Proxy ( { } , {
@@ -56,7 +60,7 @@ export function useWorkerFns<FNS extends Record<string, AnyFn>>(
5660 if ( memo . has ( name ) ) {
5761 return memo . get ( name ) ;
5862 }
59- const fn = useWorkerFn ( name , worker ) ;
63+ const fn = useWorkerFn ( name , worker , options [ name ] ) ;
6064 memo . set ( name , fn ) ;
6165 return fn ;
6266 } ,
Original file line number Diff line number Diff line change @@ -26,7 +26,11 @@ Deno.test("fns", async (t) => {
2626 type : "module" ,
2727 } ,
2828 ) ;
29- const { add, fib } = useWorkerFns < Fns > ( worker ) ;
29+ const { add, fib } = useWorkerFns < Fns > ( worker , {
30+ fib : {
31+ transfer : ( ) => [ ] ,
32+ } ,
33+ } ) ;
3034 assertEquals ( await add ( 1 , 2 ) , 3 ) ;
3135 assertEquals ( await add ( 5 , 5 ) , 10 ) ;
3236 assertEquals ( await add ( 10 , 20 ) , 30 ) ;
You can’t perform that action at this time.
0 commit comments