docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Create a utility module that demonstrates different integration patterns for waiting on multiple promises to settle. The module should provide various ways to handle promise settlement based on different application needs.
Your module should expose four different functions, each demonstrating a specific integration pattern:
Direct Integration Function (checkAllDirect): A function that accepts an array of promises and returns a promise that resolves with information about how each promise settled (fulfilled or rejected). This function should work independently without modifying any global objects.
Polyfill Selection Function (checkAllWithPolyfill): A function that intelligently selects the best available implementation - using native functionality if available and compliant, otherwise falling back to a custom implementation. It should accept an array of promises and return settlement information.
Global Integration Function (setupGlobalCheck): A function that sets up global promise settlement checking capability by adding it to the global Promise object (only if missing or non-compliant). After calling this function, developers should be able to use the settlement checking directly on the Promise object.
Automatic Setup Function (setupAutomatic): A function that automatically configures the global Promise object to support settlement checking when called, requiring no explicit setup from the calling code.
For all functions that check promise settlement:
status property that is either 'fulfilled' or 'rejected'value property containing the resolved valuereason property containing the rejection reasonGiven an array with one resolved promise (value: 42) and one rejected promise (reason: Error("failed")), checkAllDirect returns a promise that resolves to an array with two result objects: the first with status 'fulfilled' and value 42, the second with status 'rejected' and reason matching the error. @test
Given an array with one resolved promise (value: "success") and one rejected promise (reason: Error("error")), checkAllWithPolyfill returns a promise that resolves to an array with two result objects in the correct order. @test
After calling setupGlobalCheck(), the global Promise object has a settlement checking method available that can process an array of mixed promises and return proper result objects. @test
After calling setupAutomatic(), attempting to use settlement checking on the global Promise object succeeds and correctly processes promises. @test
/**
* Directly checks settlement of all promises without modifying globals
* @param {Iterable} promises - An iterable of promises or values
* @returns {Promise<Array<{status: 'fulfilled'|'rejected', value?: any, reason?: any}>>}
*/
function checkAllDirect(promises) {
// Implementation here
}
/**
* Returns the best available settlement checking implementation
* @param {Iterable} promises - An iterable of promises or values
* @returns {Promise<Array<{status: 'fulfilled'|'rejected', value?: any, reason?: any}>>}
*/
function checkAllWithPolyfill(promises) {
// Implementation here
}
/**
* Sets up global Promise settlement checking capability
* @returns {void}
*/
function setupGlobalCheck() {
// Implementation here
}
/**
* Automatically configures global Promise for settlement checking
* @returns {void}
*/
function setupAutomatic() {
// Implementation here
}
module.exports = {
checkAllDirect,
checkAllWithPolyfill,
setupGlobalCheck,
setupAutomatic
};Provides promise settlement functionality with multiple usage modes including standalone, polyfill, shim, and auto-shim patterns.