or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-10/

Promise Settlement Utility

Build a utility module that processes collections of asynchronous operations and returns comprehensive settlement results. The module must handle multiple promises simultaneously and provide detailed information about each operation's outcome, regardless of success or failure.

Requirements

Your utility should accept a collection of promises and return a promise that resolves when all input promises have settled. The result should contain information about each promise's outcome.

Core Behavior

  • Accept an iterable containing promises and/or plain values
  • Wait for all promises to complete (either fulfill or reject)
  • Return an array where each element corresponds to an input promise
  • For fulfilled promises, include the resolved value
  • For rejected promises, include the rejection reason
  • The returned promise should never reject, even if input promises reject

Result Format

Each result element should be an object containing:

  • A status field indicating whether the promise was fulfilled or rejected
  • For fulfilled promises: a value field containing the resolved value
  • For rejected promises: a reason field containing the rejection reason

Input Handling

  • Handle empty iterables correctly
  • Process mixed collections of fulfilled and rejected promises
  • Treat non-promise values as already fulfilled
  • Preserve the order of results matching the input order

Edge Cases

  • Handle iterables containing all fulfilled promises
  • Handle iterables containing all rejected promises
  • Handle iterables with a mix of promises and non-promise values
  • Handle empty iterables

Implementation

@generates

API

/**
 * Waits for all promises to settle and returns their results.
 *
 * @param {Iterable} iterable - An iterable of promises and/or values
 * @returns {Promise<Array>} A promise that resolves to an array of result objects
 */
function settleAll(iterable) {
  // Implementation here
}

module.exports = { settleAll };

Test Cases

  • Given an array with one fulfilled promise resolving to 'success' and one rejected promise with reason 'error', returns an array with two result objects: first with status 'fulfilled' and value 'success', second with status 'rejected' and reason 'error' @test

  • Given an empty array, returns an empty array @test

  • Given an array containing the number 42 (non-promise value), returns an array with one result object having status 'fulfilled' and value 42 @test

  • Given an array with three rejected promises, returns an array with three result objects all having status 'rejected' with their respective reasons @test

Dependencies { .dependencies }

promise.allsettled { .dependency }

Provides promise settlement functionality with robust method binding and environment protection.