or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-7/

Promise Settlement Utility

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.

Requirements

Your module should provide three distinct functions that leverage the promise.allsettled package's es-shims API architecture:

1. Standalone Settlement Function

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.

  • Takes an array of promises as input
  • Returns a promise that resolves with settlement results
  • Each result should indicate whether the promise was fulfilled or rejected
  • Should not modify global Promise object

2. Environment-Aware Settlement Function

Create a function getSettlementTracker that intelligently selects the best available implementation:

  • Returns a function that can track promise settlements
  • Should use the native implementation if it exists and is compliant
  • Should fall back to a polyfill implementation when native is unavailable
  • Must work across different JavaScript environments

3. Global Installation Function

Create a function installSettlementTracking that makes settlement tracking available on the global Promise object:

  • Should add settlement tracking capability to Promise if not already present
  • Should only modify Promise if necessary (don't overwrite compliant implementations)
  • After installation, Promise.allSettled should be available globally
  • Should return the function that was installed

Test Cases

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

Implementation

@generates

API

/**
 * 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
};

Dependencies { .dependencies }

promise.allsettled { .dependency }

Provides ES2020-compliant Promise.allSettled polyfill with multiple integration modes.

@satisfied-by