1
+ import { setTimeout } from 'node:timers/promises' ;
1
2
import type {
2
3
AttributeValue ,
3
4
Context ,
@@ -20,7 +21,7 @@ const asyncSqsRecordHandler = async (record: SQSRecord): Promise<string> => {
20
21
if ( body . includes ( 'fail' ) ) {
21
22
throw new Error ( 'Failed to process record.' ) ;
22
23
}
23
- await new Promise ( ( resolve ) => setTimeout ( resolve , 1 ) ) ;
24
+ await setTimeout ( 1 ) ; // simulate some processing time
24
25
return body ;
25
26
} ;
26
27
@@ -40,7 +41,7 @@ const asyncKinesisRecordHandler = async (
40
41
if ( body . includes ( 'fail' ) ) {
41
42
throw new Error ( 'Failed to process record.' ) ;
42
43
}
43
- await new Promise ( ( resolve ) => setTimeout ( resolve , 1 ) ) ;
44
+ await setTimeout ( 1 ) ; // simulate some processing time
44
45
return body ;
45
46
} ;
46
47
@@ -60,7 +61,7 @@ const asyncDynamodbRecordHandler = async (
60
61
if ( body . S ?. includes ( 'fail' ) ) {
61
62
throw new Error ( 'Failed to process record.' ) ;
62
63
}
63
- await new Promise ( ( resolve ) => setTimeout ( resolve , 1 ) ) ;
64
+ await setTimeout ( 1 ) ; // simulate some processing time
64
65
return body ;
65
66
} ;
66
67
@@ -91,7 +92,7 @@ const asyncHandlerWithContext = async (
91
92
`Context possibly malformed. Displaying context:\n${ context } `
92
93
) ;
93
94
}
94
- await new Promise ( ( resolve ) => setTimeout ( resolve , 1 ) ) ;
95
+ await setTimeout ( 1 ) ; // simulate some processing time
95
96
return record . body ;
96
97
} ;
97
98
0 commit comments