Skip to content

Commit

Permalink
jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
tannal committed Aug 13, 2024
1 parent f12dbb4 commit a4aa5fd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/common/gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ const common = require('../common');
const gcTrackerMap = new WeakMap();
const gcTrackerTag = 'NODE_TEST_COMMON_GC_TRACKER';


/**
* Installs a garbage collection listener for the specified object.
* Uses async_hooks for GC tracking, which may affect test functionality.
* A full setImmediate() invocation passes between a global.gc() call and the listener being invoked.
*
* @param {Object} obj - The target object to track for garbage collection.
* @param {Object} gcListener - The listener object containing the ongc callback.
* @param {Function} gcListener.ongc - The function to call when the target object is garbage collected.
*/
function onGC(obj, gcListener) {
const async_hooks = require('async_hooks');

Expand All @@ -30,6 +40,13 @@ function onGC(obj, gcListener) {
obj = null;
}

/**
* Repeatedly triggers garbage collection until a specified condition is met or a maximum number of attempts is reached.
*
* @param {string|function} [name] - Optional name for the test, used in the rejection message if the condition is not met.
* @param {function} condition - A function that returns true when the desired condition is met.
* @returns {Promise} A promise that resolves when the condition is met, or rejects after 10 failed attempts.
*/
function gcUntil(name, condition) {
if (typeof name === 'function') {
condition = name;
Expand Down

0 comments on commit a4aa5fd

Please sign in to comment.