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(
642642 when (state) {
643643 // SINGE/SINGLE+ state -- one completion handler
644644 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
646646 // try remove and revert back to empty state
647647 if (STATE .compareAndSet(this , state, EmptyActive )) return
648648 }
Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ class JobTest : TestBase() {
127127 var fireCount = 0
128128 for (i in 0 until n) job.invokeOnCompletion { fireCount++ }.dispose()
129129 }
130-
130+
131131 @Test
132132 fun testCancelledParent () {
133133 val parent = Job ()
@@ -136,4 +136,25 @@ class JobTest : TestBase() {
136136 val child = Job (parent)
137137 check(! child.isActive)
138138 }
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+ }
139160}
You can’t perform that action at this time.
0 commit comments