Skip to content

Propagate CancellationException in Flow/Suspend helpers; refine timeout handling and dispatcher default - #1

Closed
yangcyzhang wants to merge 1 commit into
masterfrom
codex
Closed

yangcyzhang wants to merge 1 commit into
masterfrom
codex

Conversation

@yangcyzhang

Copy link
Copy Markdown
Owner

Motivation

  • Ensure CancellationException is never swallowed by Flow helpers so coroutine cancellation and structured concurrency remain correct.
  • Avoid treating parent cancellations as timeouts in withTimeoutOrDefault so outer-scope cancellations propagate.
  • Make the library compatible with plain JVM usage by defaulting the main dispatcher to Dispatchers.Default and update docs for renamed callback helper.

Description

  • Updated Flow extensions to re-throw CancellationException in onEachCatching, flatMapLatestCatching, and mapNotNullCatching while still swallowing other exceptions.
  • Changed withTimeoutOrDefault to catch TimeoutCancellationException specifically so parent cancellations are propagated.
  • Set CoroutineKitDispatchers.main default to Dispatchers.Default for JVM support.
  • Updated README example to use callbackToFlow (renamed helper) and adjusted docs accordingly.
  • Added unit tests validating CancellationException propagation for onEachCatching, mapNotNullCatching, flatMapLatestCatching, and parent-cancellation behavior for withTimeoutOrDefault.

Testing

  • Ran unit tests with ./gradlew :coroutinekit:test and all tests (including new tests in FlowExtTest and SuspendExtTest) passed.
  • Added tests assert CancellationException is propagated for Flow helpers and that withTimeoutOrDefault does not return the fallback when the parent coroutine is cancelled, and they succeeded.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant