Sitelet https://github.com/fsprojects/FSharp.Control.R3/issues/15
Skip to content

Add onErrorResumeAsFailure, materialize and subscribeWithCallbacks, and correct the catch description #15

Description

@xperiandri

Is your feature request related to a problem? Please describe.
Code migrating from System.Reactive relies on an exception ending the sequence. In R3, an exception thrown by an operator goes to OnErrorResume and the sequence continues; OnErrorResumeAsFailure turns it into OnCompleted(Result.Failure). FSharp.Control.R3 0.3.1 has no wrapper for it.

The XML doc of catch says "Exception does not stop further processing". In fact, catch handles only failures that complete the sequence; it never sees OnErrorResume:

#r "nuget: FSharp.Control.R3, 0.3.1"
open R3
open FSharp.Control.R3

let throwing () =
    R3.Observable.ToObservable [ 1; 2; 3 ]
    |> Observable.map (fun x -> if x = 2 then failwith "boom" else x)

throwing () |> Observable.catch (fun (_ : exn) -> Observable.Return 42)
// next 1; resume boom; next 3; completed — catch is not invoked

throwing () |> _.OnErrorResumeAsFailure() |> Observable.catch (fun (_ : exn) -> Observable.Return 42)
// next 1; next 42; completed

Describe the solution you'd like

val onErrorResumeAsFailure : source : Observable<'T> -> Observable<'T>
val materialize : source : Observable<'T> -> Observable<Notification<'T>>
val dematerialize : source : Observable<Notification<'T>> -> Observable<'T>
val subscribeWithCallbacks :
    onNext : ('T -> unit) -> onErrorResume : (exn -> unit) -> onCompleted : (Result -> unit) -> source : Observable<'T> -> IDisposable
  • The catch doc states that it handles OnCompleted(Result.Failure) only and points to onErrorResumeAsFailure.

Additional context
FSharp.Data.GraphQL relies on stream failures being terminal. Its WebSocket transport subscribes with separate callbacks for items, errors and completion.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions