PromiseLogic.majority()

Composite Logic GateMAJORITY Logic - Majority voting logic, succeeds when more than half of Promises succeed

The PromiseLogic.majority() method implements MAJORITY (majority voting) logic gate semantics, succeeding when number of successful Promises exceeds half, suitable for distributed system consensus and voting decision scenarios.

Syntax

javascript
 PromiseLogic.majority(iterable)

Parameters

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

Return Value

Returns a Promise that resolves to an array of successful Promises when number of successes exceeds half.

Promise<T[]>

Behavior

Success Condition

When number of successful Promises exceeds half, returned Promise resolves to array of successful Promises.

Failure Condition

When number of successful Promises does not exceed half, returned Promise is rejected.

Examples

Basic Usage

MAJORITY Logic Example - Succeeds when majority succeed

JAVASCRIPT
Loading...

Error Handling

MAJORITY Logic Example - Majority not reached

JAVASCRIPT
Loading...

Real Application

Distributed system consensus

JAVASCRIPT
Loading...

Important Notes

  • MAJORITY logic requires number of successful Promises to exceed half
  • Suitable for scenarios requiring majority agreement, such as distributed system consensus, voting systems
  • Returns array of successful Promises for easy subsequent processing
  • Can be used to build highly fault-tolerant distributed algorithms