Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4501e7
commit f5579e6
Showing
25 changed files
with
519 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
kotlinx-coroutines-core/jsAndWasmShared/src/CoroutineContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2016-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
import kotlinx.coroutines.internal.ScopeCoroutine | ||
import kotlin.coroutines.* | ||
|
||
@PublishedApi // Used from kotlinx-coroutines-test via suppress, not part of ABI | ||
internal actual val DefaultDelay: Delay | ||
get() = Dispatchers.Default as Delay | ||
|
||
public actual fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext { | ||
val combined = coroutineContext + context | ||
return if (combined !== Dispatchers.Default && combined[ContinuationInterceptor] == null) | ||
combined + Dispatchers.Default else combined | ||
} | ||
|
||
public actual fun CoroutineContext.newCoroutineContext(addedContext: CoroutineContext): CoroutineContext { | ||
return this + addedContext | ||
} | ||
|
||
// No debugging facilities on Wasm and JS | ||
internal actual inline fun <T> withCoroutineContext(context: CoroutineContext, countOrElement: Any?, block: () -> T): T = block() | ||
internal actual inline fun <T> withContinuationContext(continuation: Continuation<*>, countOrElement: Any?, block: () -> T): T = block() | ||
internal actual fun Continuation<*>.toDebugString(): String = toString() | ||
internal actual val CoroutineContext.coroutineName: String? get() = null // not supported on Wasm and JS | ||
|
||
internal actual class UndispatchedCoroutine<in T> actual constructor( | ||
context: CoroutineContext, | ||
uCont: Continuation<T> | ||
) : ScopeCoroutine<T>(context, uCont) { | ||
override fun afterResume(state: Any?) = uCont.resumeWith(recoverResult(state, uCont)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright 2016-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
internal actual fun createDefaultDispatcher(): CoroutineDispatcher = WasiDispatcher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright 2016-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
internal actual val DEBUG: Boolean = false | ||
|
||
internal actual val Any.hexAddress: String | ||
get() = this.hashCode().toString() | ||
|
||
internal actual val Any.classSimpleName: String get() = this::class.simpleName ?: "Unknown" | ||
|
||
internal actual inline fun assert(value: () -> Boolean) {} |
11 changes: 11 additions & 0 deletions
11
kotlinx-coroutines-core/wasmWasi/src/EventLoopException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright 2016-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
/** | ||
* Thrown when multiply exception were thrown in event loop. | ||
* @see runEventLoop | ||
*/ | ||
public class EventLoopException(public val causes: List<Throwable>) : Throwable("Multiple exceptions were thrown in the event loop.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines | ||
|
||
import kotlinx.coroutines.internal.* | ||
import kotlin.coroutines.* | ||
|
||
internal object WasiDispatcher: CoroutineDispatcher(), Delay { | ||
override fun limitedParallelism(parallelism: Int): CoroutineDispatcher { | ||
parallelism.checkParallelism() | ||
return this | ||
} | ||
|
||
override fun dispatch(context: CoroutineContext, block: Runnable) { | ||
registerEvent(0) { block.run() } | ||
} | ||
|
||
override fun invokeOnTimeout(timeMillis: Long, block: Runnable, context: CoroutineContext): DisposableHandle { | ||
val event = registerEvent(delayToNanos(timeMillis)) { block.run() } | ||
return DisposableHandle { event.cancel() } | ||
} | ||
|
||
override fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>) { | ||
val event = registerEvent(delayToNanos(timeMillis)) { | ||
with(continuation) { resumeUndispatched(Unit) } | ||
} | ||
continuation.invokeOnCancellation(handler = { event.cancel() }) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
kotlinx-coroutines-core/wasmWasi/src/internal/CoroutineExceptionHandlerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright 2016-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines.internal | ||
|
||
internal actual fun propagateExceptionFinalResort(exception: Throwable) { | ||
println(exception.toString()) | ||
} |
17 changes: 17 additions & 0 deletions
17
kotlinx-coroutines-core/wasmWasi/src/internal/CoroutineRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2016-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.coroutines.internal | ||
|
||
import kotlinx.coroutines.* | ||
import kotlin.coroutines.* | ||
|
||
@InternalCoroutinesApi | ||
public fun runTestCoroutine(context: CoroutineContext, block: suspend CoroutineScope.() -> Unit) { | ||
val newContext = GlobalScope.newCoroutineContext(context) | ||
val coroutine = object: AbstractCoroutine<Unit>(newContext, true, true) {} | ||
coroutine.start(CoroutineStart.DEFAULT, coroutine, block) | ||
runEventLoop() | ||
if (coroutine.isCancelled) throw coroutine.getCancellationException().let { it.cause ?: it } | ||
} |
Oops, something went wrong.