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>(
42
42
* Invoke this function in the main thread to create proxy functions of all worker functions.
43
43
*
44
44
* @param worker - A Worker instance.
45
+ * @param options - An object containing options.
45
46
* @returns Proxy functions.
46
47
*/
47
48
export function useWorkerFns < FNS extends Record < string , AnyFn > > (
48
49
worker : MsgPort ,
50
+ options : {
51
+ [ NAME in keyof FNS ] ?: UseWorkerFnOpts < FNS [ NAME ] > ;
52
+ } = { } ,
49
53
) : ProxyFns < FNS > {
50
54
const memo = new Map < string , ProxyFn < AnyFn > > ( ) ;
51
55
const fns = new Proxy ( { } , {
@@ -56,7 +60,7 @@ export function useWorkerFns<FNS extends Record<string, AnyFn>>(
56
60
if ( memo . has ( name ) ) {
57
61
return memo . get ( name ) ;
58
62
}
59
- const fn = useWorkerFn ( name , worker ) ;
63
+ const fn = useWorkerFn ( name , worker , options [ name ] ) ;
60
64
memo . set ( name , fn ) ;
61
65
return fn ;
62
66
} ,
Original file line number Diff line number Diff line change @@ -26,7 +26,11 @@ Deno.test("fns", async (t) => {
26
26
type : "module" ,
27
27
} ,
28
28
) ;
29
- const { add, fib } = useWorkerFns < Fns > ( worker ) ;
29
+ const { add, fib } = useWorkerFns < Fns > ( worker , {
30
+ fib : {
31
+ transfer : ( ) => [ ] ,
32
+ } ,
33
+ } ) ;
30
34
assertEquals ( await add ( 1 , 2 ) , 3 ) ;
31
35
assertEquals ( await add ( 5 , 5 ) , 10 ) ;
32
36
assertEquals ( await add ( 10 , 20 ) , 30 ) ;
You can’t perform that action at this time.
0 commit comments