File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const wait = require ( 'timers/promises' ) . setTimeout ;
4+
35// TODO(joyeecheung): merge ongc.js and gcUntil from common/index.js
46// into this.
57
@@ -65,6 +67,15 @@ async function checkIfCollectable(
6567 createObject ( ) ;
6668}
6769
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+
6878module . exports = {
6979 checkIfCollectable,
80+ runAndBreathe,
7081} ;
Original file line number Diff line number Diff line change 66 */
77
88const common = require ( '../common' ) ;
9+ const { runAndBreathe } = require ( '../common/gc' ) ;
910const assert = require ( 'assert' ) ;
1011const { isMainThread, Worker } = require ( 'worker_threads' ) ;
1112
12- for ( let i = 0 ; i < 100 ; i ++ ) {
13+ runAndBreathe ( ( ) => {
1314 const realm = new ShadowRealm ( ) ;
1415 realm . evaluate ( 'new TextEncoder(); 1;' ) ;
15- }
16+ } , 100 ) . then ( common . mustCall ( ) ) ;
1617
18+ //Test it in worker too.
1719if ( isMainThread ) {
1820 const worker = new Worker ( __filename ) ;
1921 worker . on ( 'exit' , common . mustCall ( ( code ) => {
You can’t perform that action at this time.
0 commit comments