GithubHelp home page GithubHelp logo

Comments (3)

stevebrambilla avatar stevebrambilla commented on August 15, 2024 1

This could be handled by emitting a materialized signal and inspecting the results. But, I think it might also be worth considering aligning the default behavior for this with ReactiveX if possible.

It's quite common to chain async calls using flatMap, where it's expected that any failures are propagated downstream.

For example, with something like this:

_ = requestEpisode(id: epID)
	.flatMap { requestSeason(id: $0.seasonID) }
	.flatMap { requestSeries(id: $0.seriesID) }

Assuming that any of the requests could fail with an HTTPError, the final error varies depending on which request fails:

  • if the source signal (requestEpisode) failed, it would be an HTTPError
  • if either of the chained inner signals (requestSeason, requestSeries) failed, it would send the original SignalError.closed error from requestEpisode, implying success

With respect to the design difference, I find it's still similar to ReactiveSwift's idea of a "terminating event", which is either .completed, .failed, or .interrupted. For flatMap, .completed events are not forwarded from inner signals, but .failed events are. A .failed event also stops all further events from other inner signals.

I wonder if CwlSignal might want to consider some of the SignalError cases to be special errors that aren't forwarded, but continue to forward others (ie. the "true failures")?

from cwlsignal.

mattgallagher avatar mattgallagher commented on August 15, 2024

Hi Steve,

The behavior in CwlSignal on this issue is intentional but whether it represents an appropriate implementation of flatMap is a different thing.

Specifically, the transformFlatten function (CwlSignalExtensions.swift, line 109) handles this behavior. You can see that it deliberately grabs the closeError from the source signal and when all child signals plus the source are finally closed, the closeError is emitted on the output.

In your test case, you're seeing the successful SignalError.close sent by the fromSequence operator, rather than the child TestError.oneValue.

There's a design difference between typical ReactiveX and CwlSignal here: CwlSignal propagates just 1 error per signal (the first error is always the end of signal), so it can't propagate errors for each of the child signals unless it "materializes" them (wraps in an additional Result wrapper so the values and errors of the child all constitute "values" in the output).

Perhaps CwlSignal should have an additional implementation of flatMap that emits a materialized signal to handle this difference?

from cwlsignal.

mattgallagher avatar mattgallagher commented on August 15, 2024

I believe I've addressed this issue now (since CwlSignal 2.0.0-beta.10).

The old behavior – inner signals either never close the outer signal or always close the outer signal – is replaced with a new behavior that allows non-successful inner signal close conditions to propagate and close the outer signal while allowing the outer signal to continue after successful inner closes.

Specifically, the boolean closePropagation is replaced with SignalClosePropagation, an enum. This enum supports three modes: none, all (corresponding to the old values of the bool) and the new error. This error is now used in all Reactive implementations for nested signals.

from cwlsignal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.