File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -40,24 +40,29 @@ function onGC(obj, gcListener) {
4040
4141/**
4242 * Repeatedly triggers garbage collection until a specified condition is met or a maximum number of attempts is reached.
43+ * This utillity must be run in a Node.js instance that enables --expose-gc.
4344 * @param {string|Function } [name] - Optional name, used in the rejection message if the condition is not met.
4445 * @param {Function } condition - A function that returns true when the desired condition is met.
46+ * @param {number } maxCount - Maximum number of garbage collections that should be tried.
47+ * @param {object } gcOptions - Options to pass into the global gc() function.
4548 * @returns {Promise } A promise that resolves when the condition is met, or rejects after 10 failed attempts.
4649 */
47- function gcUntil ( name , condition ) {
50+ function gcUntil ( name , condition , maxCount = 10 , gcOptions ) {
4851 if ( typeof name === 'function' ) {
4952 condition = name ;
53+ maxCount = condition ;
54+ gcOptions = maxCount ;
5055 name = undefined ;
5156 }
5257 return new Promise ( ( resolve , reject ) => {
5358 let count = 0 ;
5459 function gcAndCheck ( ) {
5560 setImmediate ( ( ) => {
5661 count ++ ;
57- global . gc ( ) ;
62+ global . gc ( gcOptions ) ;
5863 if ( condition ( ) ) {
5964 resolve ( ) ;
60- } else if ( count < 10 ) {
65+ } else if ( count < maxCount ) {
6166 gcAndCheck ( ) ;
6267 } else {
6368 reject ( name === undefined ? undefined : 'Test ' + name + ' failed' ) ;
You can’t perform that action at this time.
0 commit comments