src/readiness/index.js
/**
   * SDK Readiness Gate Factory
   *
   * The ready state in the browser relay on sharing the splits ready flag across
   * all the gates, and have an extra flag for the segments which is per gate
   * instance.
   */
SDK Readiness Gate Factory
The ready state in the browser relay on sharing the splits ready flag across
all the gates, and have an extra flag for the segments which is per gate
instance.
SDK Readiness Gate Factory The ready state in the browser relay on sharing the splits ready flag across all the gates and have an extra flag for the segments which is per gate instance .
function SDKReadinessGateFactory(timeout = 0) {
    let readinessTimeoutId = 0;
    const segments = new EventEmitter();
    segments.SDK_SEGMENTS_ARRIVED = Events.SDK_SEGMENTS_ARRIVED;
    const gate = ReadinessGateFactory(splits, segments, timeout);
    if (timeout > 0) {
      readinessTimeoutId = setTimeout(() => {
        gate.emit(Events.SDK_READY_TIMED_OUT, 'Split SDK emitted SDK_READY_TIMED_OUT event.');
      }, timeout);
      gate.once(Events.SDK_READY, () => clearTimeout(readinessTimeoutId));
    }
    gate.SDK_READY = Events.SDK_READY;
    gate.SDK_UPDATE = Events.SDK_UPDATE;
    gate.SDK_READY_TIMED_OUT = Events.SDK_READY_TIMED_OUT;
    refCount++;
    return {
      splits,
      segments,
      gate,
      destroy() {
        segments.removeAllListeners();
        gate.removeAllListeners();
        clearTimeout(readinessTimeoutId);
        if (refCount > 0) refCount--;
        if (refCount === 0) splits.removeAllListeners();
      }
    };
  }
function SDKReadinessGateFactory ( timeout = 0 ) { let readinessTimeoutId = 0 ; const segments = new EventEmitter ( ) ; segments . SDK_SEGMENTS_ARRIVED = Events . SDK_SEGMENTS_ARRIVED ; const gate = ReadinessGateFactory ( splits , segments , timeout ) ; if ( timeout > 0 ) { readinessTimeoutId = setTimeout ( ( ) => { gate . emit ( Events . SDK_READY_TIMED_OUT , 'Split SDK emitted SDK_READY_TIMED_OUT event.' ) ; } , timeout ) ; gate . once ( Events . SDK_READY , ( ) => clearTimeout ( readinessTimeoutId ) ) ; } gate . SDK_READY = Events . SDK_READY ; gate . SDK_UPDATE = Events . SDK_UPDATE ; gate . SDK_READY_TIMED_OUT = Events . SDK_READY_TIMED_OUT ; refCount ++ ; return { splits , segments , gate , destroy ( ) { segments . removeAllListeners ( ) ; gate . removeAllListeners ( ) ; clearTimeout ( readinessTimeoutId ) ; if ( refCount > 0 ) refCount -- ; if ( refCount === 0 ) splits . removeAllListeners ( ) ; } } ; }
SDK Readiness Gate Factory
 The ready state in the browser relay on sharing the splits ready flag across
 all the gates, and have an extra flag for the segments which is per gate
 instance.
SDK Readiness Gate Factory The ready state in the browser relay on sharing the splits ready flag across all the gates and have an extra flag for the segments which is per gate instance .
// Add the timeout. // Clear it if the SDK get's ready. // New Gate has been created, so increase the counter // Emitters // Cleanup listeners