PromiseLogic.xor()

Core Logic GateXOR Logic - Succeeds when exactly one Promise succeeds

The PromiseLogic.xor() method implements XOR (exclusive OR) logic gate semantics, succeeding when exactly one Promise succeeds, suitable for scenarios requiring exclusive operations.

Syntax

javascript
 PromiseLogic.xor(iterable)

Parameters

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

Return Value

Returns a Promise that resolves to the value of the successful Promise when exactly one Promise succeeds.

Promise<T>

Behavior

Success Condition

When exactly one Promise resolves successfully, the returned Promise resolves to that Promise's value.

Failure Condition

When no Promise succeeds or more than one Promise succeeds, the returned Promise is rejected.

Examples

Basic Usage

XOR Logic Example - Succeeds when exactly one succeeds

JAVASCRIPT
Loading...

Error Handling

XOR Logic Failure Example - Multiple Promises succeed

JAVASCRIPT
Loading...

Real Application

Exclusive operation validation

JAVASCRIPT
Loading...

Important Notes

  • XOR logic requires exactly one Promise to succeed, otherwise it is considered a failure
  • Suitable for scenarios requiring exclusive operations, such as resource locking, uniqueness validation
  • When no Promise succeeds, returns all Promise rejection reasons
  • When multiple Promises succeed, returns an error indicating multiple operations succeeded simultaneously