electron-direct-ipc - v2.2.3
    Preparing search index...

    Class DirectIpcUtilityThrottled<TMessageMap, TInvokeMap, TIdentifierStrings>

    Note: You typically access this via directIpc.throttled rather than creating instances directly. DirectIpcUtility automatically creates a throttled instance.

    Provides automatic message throttling using microtask coalescing. This is a lossy communication pattern where intermediate messages are dropped, keeping only the latest message per event loop tick.

    Send-side coalescing:

    • Multiple sends to the same target+channel in one tick → only last message sent
    • Sends are batched and dispatched on next microtask (~1ms)
    • All pending sends dispatched in parallel for maximum throughput

    Receive-side coalescing:

    • Multiple receives on same channel in one tick → listeners called once with latest
    • Received messages queued and dispatched on next microtask
    • All listeners receive the same (latest) coalesced value

    Use directIpc.throttled when:

    • Sending high-frequency state updates (position, volume, progress)
    • Only the latest value matters (replaceable state, not events)
    • You're experiencing backpressure (sender faster than receiver)
    • Real-time data feeds where staleness is unacceptable

    Use regular directIpc when:

    • Every message is unique and important (user actions, commands)
    • Messages represent discrete events (not continuous state)
    • Order of messages matters for correctness
    • You need guaranteed delivery of every message
    • Messages trigger side effects that can't be skipped
    • Using invoke/handle pattern (already request-response, no throttling needed)

    Before using .throttled, verify ALL of these are true:

    • [ ] Your message represents replaceable state (not unique events)
    • [ ] Only the latest value matters (intermediate values can be lost)
    • [ ] Missing intermediate updates is acceptable for your use case
    • [ ] You're experiencing backpressure or very high message rates (>60Hz)
    • [ ] The message is idempotent (same value sent twice = same effect as once)

    If ANY of these are false, use regular directIpc methods instead.

    • Latency: ~1ms added latency (one microtask delay)
    • Throughput: High - parallel sends after coalescing
    • Message loss: 0% for latest value, 100% for intermediate values
    • Memory: O(channels) - one pending message per unique target+channel

    Type Parameters

    • TMessageMap extends EventMap = EventMap

      Map of message channels to handler signatures (WITHOUT sender)

    • TInvokeMap extends InvokeMap = InvokeMap

      Map of invoke channels to handler signatures (WITHOUT sender)

    • TIdentifierStrings extends string = string

      Union of allowed identifier strings

    Index

    Constructors

    Properties

    The underlying DirectIpcUtility instance Use this for non-throttled operations like invoke/handle

    getDefaultTimeout: () => number

    Type Declaration

      • (): number
      • Get the current default timeout

        Returns number

    getMap: () => DirectIpcTarget[]

    Type Declaration

    getMyIdentifier: () => TIdentifierStrings | undefined

    Type Declaration

    getRegistrationState: () => RegistrationState

    Type Declaration

    handle: <T extends string | number | symbol>(
        channel: T,
        handler: WithSender<TInvokeMap>[T],
    ) => void

    Proxy methods (bound in constructor)

    Type Declaration

      • <T extends string | number | symbol>(
            channel: T,
            handler: WithSender<TInvokeMap>[T],
        ): void
      • Register a handler for invoke calls on a specific channel

        Type Parameters

        • T extends string | number | symbol

        Parameters

        Returns void

    invoke: <K extends string | number | symbol>(
        target: Omit<
            TargetSelector<TIdentifierStrings>,
            "allIdentifiers" | "allUrls",
        >,
        channel: K,
        ...argsWithOptions: any[],
    ) => Promise<Awaited<ReturnType<TInvokeMap[K]>>>

    Type Declaration

      • <K extends string | number | symbol>(
            target: Omit<
                TargetSelector<TIdentifierStrings>,
                "allIdentifiers" | "allUrls",
            >,
            channel: K,
            ...argsWithOptions: any[],
        ): Promise<Awaited<ReturnType<TInvokeMap[K]>>>
      • Invoke a handler on another process

        Type Parameters

        • K extends string | number | symbol

        Parameters

        Returns Promise<Awaited<ReturnType<TInvokeMap[K]>>>

    removeHandler: <T extends string | number | symbol>(channel: T) => void

    Type Declaration

      • <T extends string | number | symbol>(channel: T): void
      • Remove a handler for a specific channel

        Type Parameters

        • T extends string | number | symbol

        Parameters

        • channel: T

        Returns void

    setDefaultTimeout: (ms: number) => void

    Type Declaration

      • (ms: number): void
      • Set the default timeout for invoke calls

        Parameters

        • ms: number

        Returns void

    Accessors

    Methods

    • Register a listener for throttled message reception

      Multiple messages on the same channel received in one tick will be coalesced, and the listener will be called once with the latest value on the next microtask.

      Type Parameters

      • E extends string | number | symbol

      Parameters

      • event: E

        Channel name to listen on

      • listener: WithSender<TMessageMap>[E]

        Handler function (receives sender + message args)

      Returns this

      This instance for chaining

    • Send a message to target process(es) using a TargetSelector (throttled)

      Multiple calls to the same target+channel in one tick will be coalesced, keeping only the latest message. The message is sent on the next microtask.

      Type Parameters

      • T extends string | number | symbol

      Parameters

      Returns Promise<void>

      // Send to single identifier (throttled)
      directIpc.throttled.send({ identifier: 'renderer' }, 'cursor-position', x, y)

      // Send to webContentsId (throttled)
      directIpc.throttled.send({ webContentsId: 123 }, 'update', data)

      // Send to all matching identifiers (throttled)
      directIpc.throttled.send({ allIdentifiers: /^renderer/ }, 'broadcast', msg)