-
Notifications
You must be signed in to change notification settings - Fork 88
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
Peripheral.observe
error propagation
#188
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Recent changes in #190 and #193 has reduced the number of exceptions that are propagated through observation flows, but some failures remain problematic, especially those that occur due to a connection drop in the middle of an I/O operation (that is being executed to spin up/down observations): kable/core/src/androidMain/kotlin/Connection.kt Lines 52 to 73 in 941c8ad
For a typical I/O operation, where a library consumer is wanting to write or read data, these failures can be easily caught and handled as desired. For observations (which are supposed to remain active across disconnect/reconnect) it becomes a grey area if these failures should be "ignored" or propagated (and terminate) through the observation flow. In many cases, these failures are accompanied by a connection loss, in which case it makes sense to ignore them as it is expected the library consumer will reconnect and the observation will be re-wired (and everything will carry on). But, in the case where the connection isn't lost, then the library consumer needs to be made aware that their flow observation did not spin up correctly. The dilemma is that at the time of failure, we don't know with certainty that the connection will soon be dropped — so we can't accurately make a decision to ignore the failure. Some options are:
|
Settled on option 2 in #254. |
With the current design, errors related to an observation (
Peripheral.observe
), are propagated via an exception being thrown in the flow. This allows for handling of failures via flow operators such ascatch
orretry
, but exceptions thrown in a flow are terminal events.Having the
observe
flow terminate can be problematic, as the flow is a kind of hybrid cold/hot flow, whereas it reacts (performs actions) based on the number of subscribers. When subscribers goes from0
to1
, the characteristic notifications/indications will be enabled (and appropriate descriptor written to) and the converse (when subscribers goes from1
to0
) will perform the inverse (unwinding the notification/indication setup).observe
was designed to be long-living, as in: you can subscribe and it will remain active across disconnects/reconnects (automatically re-configuring any notifications/indications as needed on reconnect). This simplifies its usage considerably but having the flow remain active across some errors states (connection drop) but not others (failure to write to config descriptor) is inconsistent. Combined with the automatic handling of spinning up/down indications/notifications, makes error handling difficult and error prone. Usingretry
would keep the flow alive for downstream subscribers but would have the adverse side-effect of spinning down/up any notifications/indications (because subscribers will momentarily go from1
to0
, then back to1
) — these operations can be expensive and are unnecessary.The design isn't yet solidified but
materialize
operator might provide a simple error handling mechanism. The challenge is being able to propagate failures without terminating theobserve
flow. It isn't clear ifmaterialize
would offer such functionality.Rather than wait for
materialize
operator to be available, theobserve
flow should propagate asealed class
of event types (either data or error). This will allow theobserve
flow to remain active when, for example, failures to spin up notifications/indications occur. Instead of throwing the exception in the flow, aObservation.Error
(or similarly named class) will be propagated. Down stream subscribers can dematerialize failures if desired, but the flow would remain active and only unexpected ("exceptional")Exception
s would be thrown from anobserve
flow (i.e. the flow would only terminate via exception due to a bug in Kable).The text was updated successfully, but these errors were encountered: