-
public final class ThreadUtilsKt
-
-
Method Summary
Modifier and Type Method Description final static UnitsuspendifyOnMain(SuspendFunction0<Unit> block)Modernized ThreadUtils that leverages OneSignalDispatchers for better thread management. final static UnitsuspendifyOnIO(SuspendFunction0<Unit> block, Function0<Unit> onComplete)Allows a non suspending function to create a scope that can call suspending functions. final static UnitsuspendifyOnIO(SuspendFunction0<Unit> block)Allows a non suspending function to create a scope that can call suspending functions. final static UnitsuspendifyOnDefault(SuspendFunction0<Unit> block)Modern utility for executing suspending code on the default dispatcher. final static UnitsuspendifyWithCompletion(Boolean useIO, SuspendFunction0<Unit> block, Function0<Unit> onComplete)Modern utility for executing suspending code with completion callback. final static UnitsuspendifyWithErrorHandling(Boolean useIO, SuspendFunction0<Unit> block, Function1<Exception, Unit> onError, Function0<Unit> onComplete)Modern utility for executing suspending code with error handling. final static JoblaunchOnIO(SuspendFunction0<Unit> block)Launch suspending code on IO dispatcher and return a Job for waiting. final static JoblaunchOnDefault(SuspendFunction0<Unit> block)Launch suspending code on Default dispatcher and return a Job for waiting. -
-
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 executeonComplete- 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 executeonError- Optional error handleronComplete- 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
-
-
-
-