PromiseLogic.race()

Core Logic GateReturns the first completed Promise (regardless of success or failure)

The PromiseLogic.race() method implements RACE (competition) logic gate semantics, returning the value of the first completed Promise, whether that Promise succeeded or failed. It returns a PromiseWithTimer instance which wraps native Promise and provides additional functionality.

Syntax

javascript
 PromiseLogic.race(iterable)

Parameters

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

Return Value

Returns a PromiseWithTimer that resolves to the value of the first completed Promise (regardless of success or failure).

PromiseWithTimer<T>

Behavior

Completion Condition

Returns the value of the first completed Promise, whether that Promise succeeded or failed.

Special Case

If the first completed Promise failed, the returned PromiseWithTimer will also be rejected.

Examples

Basic Usage

RACE Logic Example - Returns the first completed Promise

JAVASCRIPT
Loading...

Timeout Control

Add timeout control with maxTimer method

JAVASCRIPT
Loading...

Error Handling

RACE Logic Example - First completed Promise fails

JAVASCRIPT
Loading...

Real Application

Timeout control with race

JAVASCRIPT
Loading...

Important Notes

  • RACE logic behaves exactly like standard Promise.race()
  • Returns PromiseWithTimer which supports maxTimer() for timeout control
  • maxTimer can only detect timeout, cannot cancel Promise operation itself
  • Returns the first completed Promise, whether successful or failed
  • Suitable for timeout control, performance racing scenarios
  • Note: If the first completed Promise fails, the entire operation will also fail