or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-9/

Promise Batch Processor

Build a utility function that processes batches of asynchronous operations with detailed status reporting for each operation, regardless of success or failure.

Requirements

Your task is to implement a function that takes a collection of data items and an async processor function, and returns a comprehensive status report showing which items succeeded and which failed, along with their results or error messages.

The function should:

  • Accept any iterable collection (array, Set, etc.) of data items
  • Apply an async processor function to each item
  • Wait for all operations to complete
  • Return detailed results showing the status of each operation
  • Never reject the entire batch if individual items fail
  • Preserve the order of results matching the input order

Expected Behavior

Given an iterable of items and a processor function:

  • Each item should be processed independently
  • Successful operations should return an object with status: 'fulfilled' and a value property
  • Failed operations should return an object with status: 'rejected' and a reason property
  • All operations must complete before returning results
  • Mixed success/failure scenarios should be handled gracefully
  • The returned promise never rejects, even if all individual operations fail

Test Cases

  • Given an array [1, 2, 3] and a processor that succeeds for odd numbers but rejects for even numbers, returns an array of three result objects with alternating 'fulfilled' and 'rejected' statuses in the original order @test
  • Given an empty array [], returns an empty array [] @test
  • Given a Set new Set([10, 20, 30]) and a processor function, returns an array of result objects in the Set's iteration order @test
  • Given an array of values where all processor calls succeed, returns an array where every result has status: 'fulfilled' @test

Implementation

@generates

API

/**
 * Processes a batch of items asynchronously and returns status for each
 * @param {Iterable} items - Collection of items to process
 * @param {Function} processorFn - Async function to process each item
 * @returns {Promise<Array<{status: string, value?: any, reason?: any}>>}
 */
async function processBatch(items, processorFn);

Dependencies { .dependencies }

promise.allsettled { .dependency }

Provides promise settlement tracking functionality.