File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -83,15 +83,18 @@ private class AwaitAll<T>(private val deferreds: Array<out Deferred<T>>) {
83
83
84
84
private inner class DisposeHandlersOnCancel (private val nodes : Array <AwaitAllNode >) : CancelHandler() {
85
85
fun disposeAll () {
86
- nodes.forEach { it.handle.dispose() }
86
+ nodes.forEach { it.handle!! .dispose() }
87
87
}
88
88
89
89
override fun invoke (cause : Throwable ? ) { disposeAll() }
90
90
override fun toString (): String = " DisposeHandlersOnCancel[$nodes ]"
91
91
}
92
92
93
93
private inner class AwaitAllNode (private val continuation : CancellableContinuation <List <T >>, job : Job ) : JobNode<Job>(job) {
94
- lateinit var handle: DisposableHandle
94
+ private val _handle = atomic<DisposableHandle ?>(null )
95
+ var handle: DisposableHandle ?
96
+ get() = _handle .value
97
+ set(value) { _handle .value = value }
95
98
96
99
private val _disposer = atomic<DisposeHandlersOnCancel ?>(null )
97
100
var disposer: DisposeHandlersOnCancel ?
Original file line number Diff line number Diff line change @@ -313,5 +313,18 @@ class WorkerDispatcherTest : TestBase() {
313
313
finish(6 )
314
314
}
315
315
316
+ @Test
317
+ fun testAwaitAll () = runTest {
318
+ expect(1 )
319
+ val d1 = async(dispatcher) {
320
+ " A"
321
+ }
322
+ val d2 = async(dispatcher) {
323
+ " B"
324
+ }
325
+ assertEquals(" AB" , awaitAll(d1, d2).joinToString(" " ))
326
+ finish(2 )
327
+ }
328
+
316
329
private data class Data (val s : String )
317
330
}
You can’t perform that action at this time.
0 commit comments