PromiseLogic.race()
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
| Parameter | Type | Description |
|---|---|---|
| iterable | Iterable<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
Timeout Control
Add timeout control with maxTimer method
Error Handling
RACE Logic Example - First completed Promise fails
Real Application
Timeout control with race
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