File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
kotlinx-coroutines-core/src
main/kotlin/kotlinx/coroutines/experimental
test/kotlin/kotlinx/coroutines/experimental Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -642,7 +642,7 @@ public open class JobSupport(active: Boolean) : AbstractCoroutineContextElement(
642
642
when (state) {
643
643
// SINGE/SINGLE+ state -- one completion handler
644
644
is JobNode <* > -> {
645
- if (state != = this ) return // a different job node --> we were already removed
645
+ if (state != = node ) return // a different job node --> we were already removed
646
646
// try remove and revert back to empty state
647
647
if (STATE .compareAndSet(this , state, EmptyActive )) return
648
648
}
Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ class JobTest : TestBase() {
127
127
var fireCount = 0
128
128
for (i in 0 until n) job.invokeOnCompletion { fireCount++ }.dispose()
129
129
}
130
-
130
+
131
131
@Test
132
132
fun testCancelledParent () {
133
133
val parent = Job ()
@@ -136,4 +136,25 @@ class JobTest : TestBase() {
136
136
val child = Job (parent)
137
137
check(! child.isActive)
138
138
}
139
+
140
+ @Test
141
+ fun testDisposeSingleHandler () {
142
+ val job = Job ()
143
+ var fireCount = 0
144
+ val handler = job.invokeOnCompletion { fireCount++ }
145
+ handler.dispose()
146
+ job.cancel()
147
+ assertEquals(0 , fireCount)
148
+ }
149
+
150
+ @Test
151
+ fun testDisposeMultipleHandler () {
152
+ val job = Job ()
153
+ val handlerCount = 10
154
+ var fireCount = 0
155
+ val handlers = Array (handlerCount) { job.invokeOnCompletion { fireCount++ } }
156
+ handlers.forEach { it.dispose() }
157
+ job.cancel()
158
+ assertEquals(0 , fireCount)
159
+ }
139
160
}
You can’t perform that action at this time.
0 commit comments