Skip to content

Defer throwing signal work until observation - #287

Open
dajiaohuang wants to merge 1 commit into
DeclarativeHub:masterfrom
dajiaohuang:repostew/catching-deferred-20261016
Open

dajiaohuang wants to merge 1 commit into
DeclarativeHub:masterfrom
dajiaohuang:repostew/catching-deferred-20261016

Conversation

@dajiaohuang

Copy link
Copy Markdown

Problem

Signal(catching:) evaluates its throwing closure while constructing the signal and captures that single Result. Consequently subscribing twice repeats the first result rather than the work, and retry(1) cannot recover from a transient failure in that closure.

For example, a throwing producer that fails on its first invocation and returns 42 on its second is invoked only once; observing signal.retry(1) receives the cached failure, not 42. This differs from the documented cold-signal behavior and the analogous Signal(performing:) / Signal(evaluating:) initializers.

Change

Defer Result(catching:) through the existing evaluating: initializer. Add tests for deferred/per-observation execution, failure propagation, and retry recovery, including the explicit Linux test registration.

Validation

  • Swift 6.0.3, Ubuntu 24.04 (WSL), package's existing Swift language mode: swift build -j 2 passed.
  • New regressions against unchanged production code: 3 tests executed; the deferred/per-observation and retry cases failed (6 assertions), failure propagation passed.
  • After the fix: swift test -j 2 --filter 'SignalTests.test(Catching|ProductionAndObservation|Just|Sequence|Completed|Failed|Map|Filter|Retry$|Append$)': 12 tests passed.
  • Separate tiny local consumer package using normal integer values: 9 finite tests passed, covering cold operators, disposal, subjects/replay, properties/bindings, loading/retry, a bounded serial scheduler, Published, async bridges, and this throwing-factory regression.
  • git diff --check passed.

Apple runtimes/Xcode, Android, and the full upstream suite (including stress tests) were not run. Existing Swift 6 concurrency warnings remain; no Swift 6 language-mode or all-platform acceptance claim.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant