Package 

Class ThreadUtilsKt

    • Method Detail

      • suspendifyOnMain

         final static Unit suspendifyOnMain(SuspendFunction0<Unit> block)

        Modernized ThreadUtils that leverages OneSignalDispatchers for better thread management.

        This file provides utilities for bridging non-suspending code with suspending functions, now using the centralized OneSignal dispatcher system for improved resource management and consistent threading behavior across the SDK.

        Parameters:
        block - A suspending lambda to be executed on the background thread.
      • suspendifyOnIO

         final static Unit suspendifyOnIO(SuspendFunction0<Unit> block)

        Allows a non suspending function to create a scope that can call suspending functions. This is a nonblocking call, which means the scope will run on a background thread. This will return immediately!!! Uses OneSignal's centralized thread management for better resource control.

        Parameters:
        block - The suspending code to execute
      • suspendifyOnIngress

         final static Unit suspendifyOnIngress(SuspendFunction0<Unit> block, Function0<Unit> onSuccess)

        Runs short, deadline-sensitive ingress work on its isolated serial dispatcher. onSuccess runs only when block completes normally, so callers never treat a failed or cancelled handoff as done.

      • suspendifyOnDefault

         final static Unit suspendifyOnDefault(SuspendFunction0<Unit> block)

        Modern utility for executing suspending code on the default dispatcher. Uses OneSignal's centralized thread management for CPU-intensive operations.

        Parameters:
        block - The suspending code to execute
      • suspendifyOnSerialIO

         final static Unit suspendifyOnSerialIO(SuspendFunction0<Unit> block)

        Runs block on the single-thread serial IO dispatcher. Tasks from any thread execute one-at-a-time in submission order — the entry point for lifecycle handlers that need to preserve event ordering.

        Capture time-sensitive state (timestamps, "current" snapshots) on the caller's thread before invoking — the block itself may run later under load.

      • runOnSerialIO

         final static Unit runOnSerialIO(Function0<Unit> block)

        Dispatches lifecycle offload work to the serial IO thread. The block is non-suspending so callers can hand off plain (non-coroutine) work to the single serial IO worker, preserving submission order across lifecycle events.

      • suspendifyWithErrorHandling

         final static Unit suspendifyWithErrorHandling(Boolean useIO, SuspendFunction0<Unit> block, Function1<Exception, Unit> onError)

        Modern utility for executing suspending code with error handling. Uses OneSignal's centralized thread management with comprehensive error handling.

        Parameters:
        useIO - Whether to use IO scope (true) or Default scope (false)
        block - The suspending code to execute
        onError - Optional error handler
      • launchOnIO

         final static Job launchOnIO(SuspendFunction0<Unit> block)

        Launch suspending code on IO dispatcher and return a Job for waiting. This is useful when you need to wait for the background work to complete.

        Parameters:
        block - The suspending code to execute
      • launchOnDefault

         final static Job launchOnDefault(SuspendFunction0<Unit> block)

        Launch suspending code on Default dispatcher and return a Job for waiting. This is useful when you need to wait for the background work to complete.

        Parameters:
        block - The suspending code to execute
      • mainDispatcherOrNull

         final static CoroutineDispatcher mainDispatcherOrNull()

        Null when the main thread cannot be reached. Reading Dispatchers.Main proves nothing: with no Main module, coroutines returns a stub that only fails when dispatched to.

      • withMain

         final static <T extends Any> T withMain(SuspendFunction1<CoroutineScope, T> block)

        Null when the main thread cannot be reached. A nullable block result is indistinguishable from a skip, so callers that need to tell them apart should check mainDispatcherOrNull themselves.