Skip to content

Launching coroutine in channelFlow and then canceling it produces JobCancellationException #1334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gmarchelos opened this issue Jul 12, 2019 · 0 comments
Assignees
Labels
Milestone

Comments

@gmarchelos
Copy link

I have this simple flow

runBlocking(Dispatchers.Default) {
	channelFlow {
		val j = launch {
			delay(10000000)
		}

		var i = 0
		while (true) {
			delay(1000)
			send(i++)
			if (i == 3) j.cancelAndJoin()
		}
	}.collect {
		println("received: $it")
	}
}

Actual result:

received: 0
received: 1
received: 2
Exception in thread "main" kotlinx.coroutines.JobCancellationException: Job was cancelled; job=StandaloneCoroutine{Cancelled}@185d8b6

I expected to cancel launched coroutine but looks like it also cancels channelFlow.
@qwwdfsad, Is it right behaviour ?

@elizarov elizarov added the flow label Jul 14, 2019
@qwwdfsad qwwdfsad added this to the 1.3 milestone Jul 15, 2019
qwwdfsad added a commit that referenced this issue Jul 24, 2019
Concurrent work is already properly decomposed and does not expose an "partial cancellation" behaviour as other operators may do

Fixes #1334
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants