PromiseLogic.allRejected()

Extended FeatureGet all failure reasons, always returns a failure reason array

The PromiseLogic.allRejected() method is used to get reasons from all failed Promises, regardless of how many Promises succeed, it always returns a failure reason array.

This method is particularly suitable for applications that need to deeply analyze error causes, such as error monitoring systems, fault diagnosis, performance analysis, etc.

Syntax

javascript
 PromiseLogic.allRejected(iterable)

Parameters

ParameterTypeDescription
iterableIterable<Promise<T>>An iterable collection of Promise objects

Return Value

Always returns a Promise that resolves to an array of reasons from all failed Promises (may be empty).

Promise<Error[]>

Behavior

Success Condition

Waits for all Promises to complete, then returns an array of reasons from all failed Promises.

Special Case

The allRejected method never fails, even if all Promises succeed it will return an empty array.

Examples

Basic Usage

Get all failed operation reasons

JAVASCRIPT
Loading...

Error Analysis Report

Generate detailed error analysis report

JAVASCRIPT
Loading...

Fault-Tolerant System Monitoring

Monitor system errors and implement recovery strategies

JAVASCRIPT
Loading...

Combined use with allFulfilled

Complete Operation Analysis

javascript
import { PromiseLogic } from 'promise-logic';

async function analyzeOperations(operations) {
  // Parallelly get successful and failed results
  const [successfulResults, failedReasons] = await Promise.all([
    PromiseLogic.allFulfilled(operations),
    PromiseLogic.allRejected(operations)
  ]);
  
  return {
    total: operations.length,
    successful: successfulResults.length,
    failed: failedReasons.length,
    successRate: successfulResults.length / operations.length,
    successfulResults,
    failedReasons
  };
}

This combined usage can build a complete operation analysis system, simultaneously getting detailed information about successes and failures.

Important Notes

  • allRejected always returns successful results, even if all Promises succeed it returns an empty array
  • Suitable for scenarios where you need to analyze failure reasons without caring about success scenarios
  • Can be used for error monitoring, system health checks, failure analysis, etc.
  • Returned array only contains reasons from failed Promises, no success information
  • Combined with allFulfilled can build a complete operation analysis system