docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a utility module that provides flexible integration options for tracking promise settlements using the promise.allsettled package. The module should support multiple usage modes to accommodate different application requirements.
Your module should provide three distinct functions that leverage the promise.allsettled package's es-shims API architecture:
Create a function trackSettlements that directly tracks promise settlements without modifying any global objects. This function should work independently and return settlement results for an array of promises.
Create a function getSettlementTracker that intelligently selects the best available implementation:
Create a function installSettlementTracking that makes settlement tracking available on the global Promise object:
Implement the following test cases to verify your implementation:
Given three promises (one resolved with value 1, one rejected with error "fail", one resolved with value 3), trackSettlements returns an array with three result objects in order, showing status and value/reason for each @test
getSettlementTracker returns a function that, when called with an array of promises, produces the same settlement results as the standalone function @test
After calling installSettlementTracking, Promise.allSettled exists as a function on the global Promise object @test
/**
* Tracks the settlement of multiple promises without modifying globals
* @param {Array<Promise>} promises - Array of promises to track
* @returns {Promise<Array<{status: string, value?: any, reason?: any}>>} Settlement results
*/
function trackSettlements(promises) {
// Implementation here
}
/**
* Returns the best available settlement tracking function for the environment
* @returns {Function} A function that tracks promise settlements
*/
function getSettlementTracker() {
// Implementation here
}
/**
* Installs settlement tracking on the global Promise object if needed
* @returns {Function} The settlement tracking function that was installed
*/
function installSettlementTracking() {
// Implementation here
}
module.exports = {
trackSettlements,
getSettlementTracker,
installSettlementTracking
};Provides ES2020-compliant Promise.allSettled polyfill with multiple integration modes.