File tree 2 files changed +15
-2
lines changed 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ const wait = require ( 'timers/promises' ) . setTimeout ;
4
+
3
5
// TODO(joyeecheung): merge ongc.js and gcUntil from common/index.js
4
6
// into this.
5
7
@@ -65,6 +67,15 @@ async function checkIfCollectable(
65
67
createObject ( ) ;
66
68
}
67
69
70
+ // Repeat an operation and give GC some breathing room at every iteration.
71
+ async function runAndBreathe ( fn , repeat , waitTime = 20 ) {
72
+ for ( let i = 0 ; i < repeat ; i ++ ) {
73
+ await fn ( ) ;
74
+ await wait ( waitTime ) ;
75
+ }
76
+ }
77
+
68
78
module . exports = {
69
79
checkIfCollectable,
80
+ runAndBreathe,
70
81
} ;
Original file line number Diff line number Diff line change 6
6
*/
7
7
8
8
const common = require ( '../common' ) ;
9
+ const { runAndBreathe } = require ( '../common/gc' ) ;
9
10
const assert = require ( 'assert' ) ;
10
11
const { isMainThread, Worker } = require ( 'worker_threads' ) ;
11
12
12
- for ( let i = 0 ; i < 100 ; i ++ ) {
13
+ runAndBreathe ( ( ) => {
13
14
const realm = new ShadowRealm ( ) ;
14
15
realm . evaluate ( 'new TextEncoder(); 1;' ) ;
15
- }
16
+ } , 100 ) . then ( common . mustCall ( ) ) ;
16
17
18
+ //Test it in worker too.
17
19
if ( isMainThread ) {
18
20
const worker = new Worker ( __filename ) ;
19
21
worker . on ( 'exit' , common . mustCall ( ( code ) => {
You can’t perform that action at this time.
0 commit comments