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, Function0<Unit> onComplete)

        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!!! Also provides an optional onComplete.

        Parameters:
        block - A suspending lambda to be executed on the background thread.
        onComplete - An optional lambda that will be invoked on the same background thread after block has finished executing.
      • 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
      • 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
      • suspendifyWithCompletion

         final static Unit suspendifyWithCompletion(Boolean useIO, SuspendFunction0<Unit> block, Function0<Unit> onComplete)

        Modern utility for executing suspending code with completion callback. Uses OneSignal's centralized thread management for better resource control.

        Parameters:
        useIO - Whether to use IO scope (true) or Default scope (false)
        block - The suspending code to execute
        onComplete - Optional callback to execute after completion
      • suspendifyWithErrorHandling

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

        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
        onComplete - Optional completion 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