synchronizedOn

expect fun <T> synchronizedOn(obj: Any, action: () -> T): T

Runs action while holding the monitor/lock associated with obj, returning its result; a platform-agnostic, expression-based counterpart of the JVM's synchronized(obj) { ... } block, usable from common code. On platforms without real concurrency (e.g. JS), this may simply invoke action directly, since no synchronization is needed there.

actual fun <T> synchronizedOn(obj: Any, action: () -> T): T

Runs action while holding the monitor/lock associated with obj, returning its result; a platform-agnostic, expression-based counterpart of the JVM's synchronized(obj) { ... } block, usable from common code. On platforms without real concurrency (e.g. JS), this may simply invoke action directly, since no synchronization is needed there.

actual fun <T> synchronizedOn(obj: Any, action: () -> T): T

Runs action while holding the monitor/lock associated with obj, returning its result; a platform-agnostic, expression-based counterpart of the JVM's synchronized(obj) { ... } block, usable from common code. On platforms without real concurrency (e.g. JS), this may simply invoke action directly, since no synchronization is needed there.