@@ -5,12 +5,21 @@ import { expose } from './expose.js';
55 * This is an example worker script used purely for example and internal testing
66 */
77const worker = {
8+ /**
9+ * A test function that returns the string 'hello world!'.
10+ */
811 test : async ( ) : Promise < { data : 'hello world!' } > => {
912 return { data : 'hello world!' } ;
1013 } ,
14+ /**
15+ * Adds two parameters `a` and `b` together.
16+ */
1117 add : async ( data : { a : number ; b : number } ) => {
1218 return { data : data . a + data . b } ;
1319 } ,
20+ /**
21+ * Subtracts two parameters `a` and `b` together.
22+ */
1423 sub : async ( data : { a : number ; b : number } ) => {
1524 return { data : data . a - data . b } ;
1625 } ,
@@ -21,6 +30,10 @@ const worker = {
2130 }
2231 return { data : acc } ;
2332 } ,
33+ /**
34+ * Sleeps for the provided amount of time in milliseconds.
35+ * @param data
36+ */
2437 sleep : async ( data : number ) => {
2538 await new Promise < void > ( ( resolve ) => {
2639 const timer = setTimeout ( resolve , data ) ;
@@ -29,6 +42,9 @@ const worker = {
2942 } ) ;
3043 return { data : undefined } ;
3144 } ,
45+ /**
46+ * Test function that takes a transferred ArrayBuffer and fills it with 0x0F bytes.
47+ */
3248 transferBuffer : async ( data : ArrayBuffer , _transferList ?: [ ArrayBuffer ] ) => {
3349 const buffer = Buffer . from ( data , 0 , data . byteLength ) ;
3450 buffer . fill ( 0xf ) ;
0 commit comments