PromiseLogic.or()
Core Logic GateOR Logic - Returns first successful Promise
The PromiseLogic.or() method implements OR logic gate semantics, returning value of first Promise that resolves successfully. It returns a PromiseWithTimer instance which wraps native Promise and provides additional functionality.
Syntax
javascript PromiseLogic.or(iterable)
Parameters
| Parameter | Type | Description |
|---|---|---|
| iterable | Iterable<Promise<T>> | An iterable collection of Promise objects |
Return Value
Returns a PromiseWithTimer that resolves to value of first successful Promise.
PromiseWithTimer<T>Behavior
Success Condition
Returns value of first Promise that resolves successfully.
Failure Condition
When all input Promises are rejected, PromiseWithTimer is rejected with an AggregateError containing all rejection reasons.
Error Types
AggregateErrorThrown when all input Promises fail, containing all rejection reasons
Examples
Basic Usage
OR Logic Example - Returns first successful Promise
JAVASCRIPT
Loading...
Error Handling
OR Logic Failure Example - All Promises fail
JAVASCRIPT
Loading...
Timeout Control
Add timeout control with maxTimer method
JAVASCRIPT
Loading...
Real Application
Service degradation strategy with timeout
JAVASCRIPT
Loading...
Important Notes
- • OR logic behaves similarly to standard Promise.any(), but provides more intuitive logical semantics
- • Returns PromiseWithTimer which supports maxTimer() for timeout control
- • maxTimer can only detect timeout, cannot cancel Promise operation itself
- • Suitable for scenarios requiring service degradation or failover
- • When all Promises fail, returns AggregateError containing all failure reasons
- • For scenarios where all operations must succeed, consider using PromiseLogic.and()