I have F# code that looks like this:
module O = Control.Observable
//...
use ss = serve' 4000
|> O.subscribe
(fun c -> use cs = RSS.items
|> O.subscribe (bytes >> c.SendAll) |> ignore)
where
serve' : int -> IObservable<Socket>
c : Socket
RSS.items : IObservable<XElement>
bytes : XElement -> byte []
c.SendAll : byte [] -> unit
- What is the most idiomatic way to retain
cs
untilc.SendAll
fails? - Is there or is it possible to define
Observable.subscribeUntilError(action)
where ifaction
fails, subscription gets disposed; otherwiseaction
is run as long asIObservable
keeps pushing?
I have come up with this:
To demonstrate the difference, try in
main
!Using
subscribe
:application comes crashing down:
Now using
subscribeUE
:delightfully disposes subscription
x
, application continues to run without a hiccup and exits normally! Output withLOG = ignore
:I would love to know whether comparable functionality actually exists somewhere in RX 2.0 as I find this combinator to be too useful to leave out.