-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Showing
34 changed files
with
1,043 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
out/ | ||
build/ | ||
*.iml | ||
local.properties | ||
local.properties | ||
kotlin-js-store/ |
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
8 changes: 8 additions & 0 deletions
8
...machine-coroutines/src/blockingMain/kotlin/ru/nsk/kstatemachine/coroutines/RunBlocking.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,8 @@ | ||
package ru.nsk.kstatemachine.coroutines | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.runBlocking | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
internal actual fun <T> doRunBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T = | ||
runBlocking(context, block) |
22 changes: 22 additions & 0 deletions
22
...c/blockingMain/kotlin/ru/nsk/kstatemachine/statemachine/CoroutinesStateMachineBlocking.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,22 @@ | ||
package ru.nsk.kstatemachine.statemachine | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import ru.nsk.kstatemachine.coroutines.CoroutinesLibCoroutineAbstraction | ||
import ru.nsk.kstatemachine.coroutines.createStateMachine | ||
import ru.nsk.kstatemachine.state.ChildMode | ||
|
||
/** | ||
* Blocking [createStateMachine] alternative | ||
*/ | ||
fun createStateMachineBlocking( | ||
scope: CoroutineScope, | ||
name: String? = null, | ||
childMode: ChildMode = ChildMode.EXCLUSIVE, | ||
start: Boolean = true, | ||
creationArguments: StateMachine.CreationArguments = StateMachine.CreationArguments(), | ||
init: suspend BuildingStateMachine.() -> Unit | ||
) = with(CoroutinesLibCoroutineAbstraction(scope)) { | ||
runBlocking { | ||
createStateMachine(name, childMode, start, creationArguments, init) | ||
} | ||
} |
19 changes: 11 additions & 8 deletions
19
...rc/commonMain/kotlin/ru/nsk/kstatemachine/coroutines/CoroutinesLibCoroutineAbstraction.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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
package ru.nsk.kstatemachine.coroutines | ||
|
||
import kotlinx.coroutines.* | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
internal class CoroutinesLibCoroutineAbstraction(private val scope: CoroutineScope) : CoroutineAbstraction { | ||
/** | ||
* Calls [kotlinx.coroutines.runBlocking] | ||
*/ | ||
override fun <R : Any> runBlocking(block: suspend () -> R) = | ||
runBlocking(scope.coroutineContext) { block() } | ||
internal class CoroutinesLibCoroutineAbstraction(internal val scope: CoroutineScope) : CoroutineAbstraction { | ||
override fun <R : Any> runBlocking(block: suspend () -> R): R = | ||
doRunBlocking(scope.coroutineContext) { block() } | ||
|
||
/** Switches to context of the [scope] */ | ||
override suspend fun <R : Any> withContext(block: suspend () -> R) : R = | ||
override suspend fun <R : Any> withContext(block: suspend () -> R): R = | ||
withContext(scope.coroutineContext) { block() } | ||
} | ||
} | ||
|
||
/** | ||
* Calls [kotlinx.coroutines.runBlocking] on supporting platforms, otherwise throws | ||
*/ | ||
internal expect fun <T> doRunBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T |
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
11 changes: 11 additions & 0 deletions
11
.../jsCommonMain/kotlin/ru/nsk/kstatemachine/coroutines/CoroutinesLibCoroutineAbstraction.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 @@ | ||
package ru.nsk.kstatemachine.coroutines | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import ru.nsk.kstatemachine.statemachine.StateMachine | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
internal actual fun <T> doRunBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T = | ||
throw UnsupportedOperationException( | ||
"This platform does not support kotlinx.coroutines.runBlocking(). " + | ||
"Do not use blocking API or use ${StateMachine::class.simpleName} without coroutines support" | ||
) |
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
Oops, something went wrong.