PromiseLogic.majority()
The PromiseLogic.majority() method implements MAJORITY (majority voting) logic gate semantics, succeeding when number of successful Promises exceeds to threshold. It returns a PromiseWithTimer instance which wraps native Promise and provides additional functionality.
Syntax
javascript PromiseLogic.majority(iterable, options?)
Parameters
| Parameter | Type | Description |
|---|---|---|
| iterable | Iterable<Promise<T>> | An iterable collection of Promise objects |
| options | { max?: number } | Optional configuration object. max specifies success threshold (default 0.5, range 0-1) |
Return Value
Returns a PromiseWithTimer that resolves to array of successful Promise results when majority threshold is met.
PromiseWithTimer<T[]>Behavior
Success Condition
When number of successful Promises exceeds to threshold (default 0.5), PromiseWithTimer resolves to array of successful results.
Failure Condition
When number of successful Promises does not exceed threshold, PromiseWithTimer is rejected.
Error Types
Examples
Basic Usage
MAJORITY Logic Example - Succeeds when majority succeed
Custom Threshold
MAJORITY Logic with custom threshold
Error Handling
MAJORITY Logic Example - Majority not reached
Timeout Control
Add timeout control with maxTimer method
Real Application
Distributed system consensus with timeout
Important Notes
- • MAJORITY logic requires number of successful Promises to exceed threshold (default 0.5)
- • Returns PromiseWithTimer which supports maxTimer() for timeout control
- • maxTimer can only detect timeout, cannot cancel Promise operation itself
- • Suitable for scenarios requiring majority agreement, such as distributed system consensus, voting systems
- • Custom threshold can be set via options.max parameter (range 0-1)
- • Returns array of successful Promise results when condition is met