Skip to content

Commit 45d4562

Browse files
authored
Merge pull request #120 from mmkolpakov/fix/kmp-hierarchy
Fix: KMP dependency resolution for native and Wasm targets
2 parents 38596ff + 1076ebe commit 45d4562

File tree

8 files changed

+62
-26
lines changed

8 files changed

+62
-26
lines changed

kstatemachine-coroutines/build.gradle.kts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,5 @@ kotlin {
4545
}
4646
}
4747

48-
// contains blocking APIs which are not supported on JS
49-
val blockingMain by creating { dependsOn(commonMain.get()) }
50-
val jsCommonMain by creating { dependsOn(commonMain.get()) }
51-
52-
jvmMain.get().dependsOn(blockingMain)
53-
iosMain.get().dependsOn(blockingMain)
54-
macosMain.get().dependsOn(blockingMain)
55-
linuxMain.get().dependsOn(blockingMain)
56-
mingwMain.get().dependsOn(blockingMain)
57-
58-
val wasmJsMain by getting
59-
wasmJsMain.dependsOn(jsCommonMain)
60-
jsMain.get().dependsOn(jsCommonMain)
6148
}
6249
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Author: Mikhail Fedotov
3+
* Github: https://github.com/KStateMachine
4+
* Copyright (c) 2024.
5+
* All rights reserved.
6+
*/
7+
8+
package ru.nsk.kstatemachine.coroutines
9+
10+
import kotlinx.coroutines.CoroutineScope
11+
import kotlinx.coroutines.runBlocking
12+
import kotlin.coroutines.CoroutineContext
13+
14+
internal actual fun <T> doRunBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T =
15+
runBlocking(context, block)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Author: Mikhail Fedotov
3+
* Github: https://github.com/KStateMachine
4+
* Copyright (c) 2024.
5+
* All rights reserved.
6+
*/
7+
8+
package ru.nsk.kstatemachine.statemachine
9+
10+
import kotlinx.coroutines.CoroutineScope
11+
import ru.nsk.kstatemachine.coroutines.CoroutinesLibCoroutineAbstraction
12+
import ru.nsk.kstatemachine.coroutines.createStateMachine
13+
import ru.nsk.kstatemachine.state.ChildMode
14+
15+
/**
16+
* Blocking [createStateMachine] alternative
17+
*/
18+
fun createStateMachineBlocking(
19+
scope: CoroutineScope,
20+
name: String? = null,
21+
childMode: ChildMode = ChildMode.EXCLUSIVE,
22+
start: Boolean = true,
23+
creationArguments: CreationArguments = buildCreationArguments {},
24+
init: suspend BuildingStateMachine.() -> Unit
25+
) = with(CoroutinesLibCoroutineAbstraction(scope)) {
26+
runBlocking {
27+
createStateMachine(name, childMode, start, creationArguments, init)
28+
}
29+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Author: Mikhail Fedotov
3+
* Github: https://github.com/KStateMachine
4+
* Copyright (c) 2024.
5+
* All rights reserved.
6+
*/
7+
8+
package ru.nsk.kstatemachine.coroutines
9+
10+
import kotlinx.coroutines.CoroutineScope
11+
import ru.nsk.kstatemachine.statemachine.StateMachine
12+
import kotlin.coroutines.CoroutineContext
13+
14+
internal actual fun <T> doRunBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T =
15+
throw UnsupportedOperationException(
16+
"This platform does not support kotlinx.coroutines.runBlocking(). " +
17+
"Do not use blocking API or use ${StateMachine::class.simpleName} without coroutines support"
18+
)

kstatemachine-serialization/build.gradle.kts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,5 @@ kotlin {
4646
}
4747
}
4848

49-
// contains blocking APIs which are not supported on JS
50-
val blockingMain by creating { dependsOn(commonMain.get()) }
51-
val jsCommonMain by creating { dependsOn(commonMain.get()) }
52-
53-
jvmMain.get().dependsOn(blockingMain)
54-
iosMain.get().dependsOn(blockingMain)
55-
macosMain.get().dependsOn(blockingMain)
56-
linuxMain.get().dependsOn(blockingMain)
57-
mingwMain.get().dependsOn(blockingMain)
58-
59-
val wasmJsMain by getting
60-
wasmJsMain.dependsOn(jsCommonMain)
61-
jsMain.get().dependsOn(jsCommonMain)
6249
}
6350
}

0 commit comments

Comments
 (0)