or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-8/

Promise Settlement Handler

Build a utility that processes collections of asynchronous operations and provides detailed settlement information. The utility should handle various input types including promises, regular values, and promise-like objects (thenables).

Requirements

Your implementation should:

  1. Accept an iterable of mixed values (promises, thenables, and regular values)
  2. Wait for all asynchronous operations to complete
  3. Return structured results indicating whether each operation succeeded or failed
  4. Handle promise-like objects (thenables) correctly by resolving them
  5. Never reject - always resolve with complete settlement information

Input Handling

The utility must correctly process:

  • Standard Promise objects
  • Promise-like objects with a then method (thenables)
  • Non-promise values (which should be treated as already fulfilled)
  • Empty collections

Output Format

For each input item, return an object with:

  • A status field indicating fulfillment or rejection
  • A value field for successful operations
  • A reason field for failed operations

Implementation

@generates

API

/**
 * Processes a collection of values/promises and returns settlement information
 * @param {Iterable} items - Collection of promises, thenables, or values
 * @returns {Promise<Array>} Promise resolving to array of settlement objects
 */
function processSettlements(items) {
  // Implementation here
}

module.exports = { processSettlements };

Test Cases

  • When given an array containing Promise.resolve(42), Promise.reject(new Error('failed')), and the plain value 'direct', it returns an array with three objects: {status: 'fulfilled', value: 42}, {status: 'rejected', reason: Error('failed')}, and {status: 'fulfilled', value: 'direct'} @test
  • When given an array containing a thenable object {then: (resolve) => resolve('thenable-value')}, it correctly resolves the thenable and returns {status: 'fulfilled', value: 'thenable-value'} in the results @test
  • When given an empty array [], it returns an empty array [] @test

Dependencies { .dependencies }

promise.allsettled { .dependency }

Provides promise settlement tracking with spec-compliant handling of various input types.