Skip to content

Commit ada89ae

Browse files
committed
Add basic signal waiter
1 parent e280b64 commit ada89ae

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

harness/tests/scripts/godot/tests/Invocation.gdj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ fqName = godot.tests.Invocation
66
relativeSourcePath = src/main/kotlin/godot/tests/Invocation.kt
77
baseType = Node3D
88
supertypes = [
9-
godot.Node3D,
9+
godot.Node3D,
1010
godot.Node,
1111
godot.Object,
1212
godot.core.KtObject,
1313
kotlin.Any
1414
]
1515
signals = [
16-
no_param,
16+
no_param,
1717
one_param,
1818
two_param,
1919
signal_with_multiple_targets
2020
]
2121
properties = [
22-
button,
22+
button,
2323
enum_list,
2424
vector_list,
2525
enum_list_mutable,
@@ -78,7 +78,7 @@ properties = [
7878
array
7979
]
8080
functions = [
81-
target_function_one,
81+
target_function_one,
8282
target_function_two,
8383
int_value,
8484
long_value,
@@ -171,4 +171,4 @@ functions = [
171171
nullable_string_is_null,
172172
nullable_return_type,
173173
create_variant_array_of_user_type
174-
]
174+
]

harness/tests/src/main/kotlin/godot/tests/Invocation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ class Invocation : Node3D() {
396396
override fun _ready() {
397397
GodotCoroutine{
398398
println("Before")
399-
signalWithMultipleTargets.await()
399+
noParam.await()
400400
println("After")
401401
}
402402

kt/godot-coroutine-library/src/main/kotlin/godot/coroutines/GodotContinuation.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

kt/godot-coroutine-library/src/main/kotlin/godot/coroutines/GodotCoroutine.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ object GodotCoroutine {
1010
private val scope = CoroutineScope(EmptyCoroutineContext)
1111

1212
operator fun invoke( block: suspend CoroutineScope.() -> Unit) {
13-
scope.launch(Dispatchers.Default, CoroutineStart.DEFAULT, block)
13+
scope.launch(Dispatchers.Unconfined, CoroutineStart.DEFAULT, block)
1414
}
1515
}
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package godot.coroutines
22

3-
import godot.signals.Signal
4-
import kotlinx.coroutines.delay
3+
import godot.Object
4+
import godot.signals.Signal0
5+
import godot.signals.connect
56

6-
suspend fun Signal.await() {
7-
delay(1000)
7+
import kotlinx.coroutines.CancellableContinuation
8+
import kotlinx.coroutines.suspendCancellableCoroutine
9+
import kotlin.coroutines.resume
10+
11+
12+
suspend fun Signal0.await() {
13+
return suspendCancellableCoroutine { cont: CancellableContinuation<Unit> ->
14+
connect(Object.ConnectFlags.CONNECT_ONE_SHOT.id.toInt()){
15+
cont.resume(Unit)
16+
}
17+
}
818
}
919

0 commit comments

Comments
 (0)