@@ -5,12 +5,21 @@ import { expose } from './expose.js';
5
5
* This is an example worker script used purely for example and internal testing
6
6
*/
7
7
const worker = {
8
+ /**
9
+ * A test function that returns the string 'hello world!'.
10
+ */
8
11
test : async ( ) : Promise < { data : 'hello world!' } > => {
9
12
return { data : 'hello world!' } ;
10
13
} ,
14
+ /**
15
+ * Adds two parameters `a` and `b` together.
16
+ */
11
17
add : async ( data : { a : number ; b : number } ) => {
12
18
return { data : data . a + data . b } ;
13
19
} ,
20
+ /**
21
+ * Subtracts two parameters `a` and `b` together.
22
+ */
14
23
sub : async ( data : { a : number ; b : number } ) => {
15
24
return { data : data . a - data . b } ;
16
25
} ,
@@ -21,6 +30,10 @@ const worker = {
21
30
}
22
31
return { data : acc } ;
23
32
} ,
33
+ /**
34
+ * Sleeps for the provided amount of time in milliseconds.
35
+ * @param data
36
+ */
24
37
sleep : async ( data : number ) => {
25
38
await new Promise < void > ( ( resolve ) => {
26
39
const timer = setTimeout ( resolve , data ) ;
@@ -29,6 +42,9 @@ const worker = {
29
42
} ) ;
30
43
return { data : undefined } ;
31
44
} ,
45
+ /**
46
+ * Test function that takes a transferred ArrayBuffer and fills it with 0x0F bytes.
47
+ */
32
48
transferBuffer : async ( data : ArrayBuffer , _transferList ?: [ ArrayBuffer ] ) => {
33
49
const buffer = Buffer . from ( data , 0 , data . byteLength ) ;
34
50
buffer . fill ( 0xf ) ;
0 commit comments