CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jetbrains-kotlinx--kotlinx-coroutines-core-iosx64

Kotlin coroutines library providing comprehensive asynchronous programming support with structured concurrency for iOS x64 platforms

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

kotlinx-coroutines-core

kotlinx-coroutines-core is a comprehensive Kotlin multiplatform library that provides structured concurrency support for asynchronous programming. It offers coroutine builders, reactive flows, communication channels, synchronization primitives, and platform-specific integrations while maintaining structured concurrency principles and automatic cancellation support.

Package Information

  • Package Name: org.jetbrains.kotlinx:kotlinx-coroutines-core-iosx64
  • Package Type: maven
  • Language: Kotlin (multiplatform)
  • Installation: Add to your build.gradle.kts dependencies:
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-iosx64:1.10.2")

Core Imports

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.sync.*

For specific imports:

import kotlinx.coroutines.launch
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.sync.Mutex

Basic Usage

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*

class CoroutineExample {
    suspend fun basicUsage() {
        // Create a coroutine scope
        val scope = CoroutineScope(Dispatchers.Default)
        
        // Launch fire-and-forget coroutines
        val job = scope.launch {
            delay(100)
            println("Hello from coroutine!")
        }
        
        // Launch concurrent computation
        val deferred = scope.async {
            delay(50)
            "Result from async"
        }
        
        // Work with flows
        val flow = flowOf(1, 2, 3, 4, 5)
            .map { it * 2 }
            .filter { it > 5 }
        
        flow.collect { value ->
            println("Flow value: $value")
        }
        
        // Wait for completion
        val result = deferred.await()
        job.join()
    }
}

Architecture

kotlinx-coroutines-core is built around several key architectural components:

  • Structured Concurrency: Job hierarchy ensures automatic cleanup and cancellation propagation
  • Coroutine Builders: launch, async, runBlocking for creating different types of coroutines
  • Dispatchers: Context switching for different execution environments (Main, Default, IO, Unconfined)
  • Flow API: Cold reactive streams with comprehensive operators and hot flows (SharedFlow/StateFlow)
  • Channels: Communication primitives between coroutines with various buffer strategies
  • Synchronization: Mutex and Semaphore for coordination without blocking threads
  • Platform Integration: Native support for platform-specific threading models and async APIs

Capabilities

Coroutine Management

Core lifecycle management for coroutines including Job interface, scoping, and structured concurrency support.

interface Job : CoroutineContext.Element {
    val isActive: Boolean
    val isCompleted: Boolean
    val isCancelled: Boolean
    val children: Sequence<Job>
    fun start(): Boolean
    fun cancel(): Unit
    suspend fun join(): Unit
}

interface CoroutineScope {
    val coroutineContext: CoroutineContext
}

fun CoroutineScope(context: CoroutineContext): CoroutineScope
fun MainScope(): CoroutineScope

Coroutine Management

Coroutine Builders

Functions for creating and launching coroutines with different execution patterns and result handling.

fun CoroutineScope.launch(
    context: CoroutineContext = EmptyCoroutineContext,
    start: CoroutineStart = CoroutineStart.DEFAULT,
    block: suspend CoroutineScope.() -> Unit
): Job

fun <T> CoroutineScope.async(
    context: CoroutineContext = EmptyCoroutineContext,
    start: CoroutineStart = CoroutineStart.DEFAULT,
    block: suspend CoroutineScope.() -> T
): Deferred<T>

suspend fun <T> withContext(
    context: CoroutineContext,
    block: suspend CoroutineScope.() -> T
): T

Coroutine Builders

Flow API

Cold reactive streams with comprehensive transformation operators, hot flows for state and event broadcasting.

interface Flow<out T> {
    suspend fun collect(collector: FlowCollector<T>)
}

interface FlowCollector<in T> {
    suspend fun emit(value: T)
}

fun <T> flow(block: suspend FlowScope<T>.() -> Unit): Flow<T>
fun <T> flowOf(vararg elements: T): Flow<T>

interface SharedFlow<out T> : Flow<T> {
    val replayCache: List<T>
}

interface StateFlow<out T> : SharedFlow<T> {
    val value: T
}

Flow API

Channels

Communication primitives between coroutines with various buffering strategies and channel types.

interface SendChannel<in E> {
    val isClosedForSend: Boolean
    suspend fun send(element: E)
    fun trySend(element: E): ChannelResult<Unit>
    fun close(cause: Throwable? = null): Boolean
}

interface ReceiveChannel<out E> {
    val isClosedForReceive: Boolean
    val isEmpty: Boolean
    suspend fun receive(): E
    fun tryReceive(): ChannelResult<E>
}

interface Channel<E> : SendChannel<E>, ReceiveChannel<E>

fun <E> Channel(
    capacity: Int = RENDEZVOUS,
    onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND,
    onUndeliveredElement: ((E) -> Unit)? = null
): Channel<E>

Channels

Synchronization

Non-blocking synchronization primitives including mutex and semaphore for coroutine coordination.

interface Mutex {
    val isLocked: Boolean
    suspend fun lock(owner: Any? = null)
    fun unlock(owner: Any? = null)
    fun tryLock(owner: Any? = null): Boolean
}

suspend fun <T> Mutex.withLock(
    owner: Any? = null,
    action: suspend () -> T
): T

interface Semaphore {
    val availablePermits: Int
    suspend fun acquire()
    fun release()
    fun tryAcquire(): Boolean
}

Synchronization

Dispatchers

Execution context control for coroutines including standard dispatchers and custom dispatcher creation.

abstract class CoroutineDispatcher : ContinuationInterceptor {
    abstract fun dispatch(context: CoroutineContext, block: Runnable)
    open fun isDispatchNeeded(context: CoroutineContext): Boolean
    fun limitedParallelism(parallelism: Int): CoroutineDispatcher
}

object Dispatchers {
    val Default: CoroutineDispatcher
    val Main: MainCoroutineDispatcher
    val Unconfined: CoroutineDispatcher
    val IO: CoroutineDispatcher
}

Dispatchers

Select Expression

Multi-way suspending choice allowing selection among multiple suspend operations.

suspend fun <R> select(builder: SelectBuilder<R>.() -> Unit): R

interface SelectBuilder<in R> {
    fun <T> SelectClause1<T>.invoke(block: suspend (T) -> R)
    fun SelectClause0.invoke(block: suspend () -> R)
    fun onTimeout(timeMillis: Long, block: suspend () -> R)
}

Select Expression

Error Handling & Cancellation

Cancellation propagation, exception handling, and timeout management for robust coroutine applications.

open class CancellationException : IllegalStateException

suspend fun <T> withTimeout(timeoutMillis: Long, block: suspend CoroutineScope.() -> T): T
suspend fun <T> withTimeoutOrNull(timeoutMillis: Long, block: suspend CoroutineScope.() -> T): T?

class TimeoutCancellationException : CancellationException

interface CoroutineExceptionHandler : CoroutineContext.Element {
    fun handleException(context: CoroutineContext, exception: Throwable)
}

Error Handling & Cancellation

Types

Core Context Types

enum class CoroutineStart {
    DEFAULT,
    LAZY,
    ATOMIC,
    UNDISPATCHED
}

interface Deferred<out T> : Job {
    suspend fun await(): T
    fun getCompleted(): T
    fun getCompletionExceptionOrNull(): Throwable?
}

interface CompletableJob : Job {
    fun complete(): Boolean
    fun completeExceptionally(exception: Throwable): Boolean
}

interface CompletableDeferred<T> : Deferred<T>, CompletableJob

data class CoroutineName(val name: String) : CoroutineContext.Element

Buffer & Flow Types

enum class BufferOverflow {
    SUSPEND,
    DROP_OLDEST,
    DROP_LATEST
}

interface SharingStarted {
    companion object {
        val Eagerly: SharingStarted
        val Lazily: SharingStarted
        fun WhileSubscribed(
            stopTimeoutMillis: Long = 0,
            replayExpirationMillis: Long = Long.MAX_VALUE
        ): SharingStarted
    }
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.jetbrains.kotlinx/kotlinx-coroutines-core-iosx64@1.10.x
Publish Source
CLI
Badge
tessl/maven-org-jetbrains-kotlinx--kotlinx-coroutines-core-iosx64 badge