This is the same as How to wait for a response from an RX object without introducing a race condition? but in F #.
The C # solution is as follows:
static async void Foo() { var subject = new Subject<int>(); var firstInt = subject.FirstAsync().PublishLast(); firstInt.Connect(); subject.OnNext(42); var x = await firstInt; Console.WriteLine("Done waiting: " + x); }
My attempt in F # is as follows:
let foo () = async { use subject = new Subject<int>() let firstInt = subject.FirstAsync().PublishLast() firstInt.Connect() |> ignore subject.OnNext(42) let! x = firstInt printfn "Done waiting: %d" x return () }
let x! = firstInt let x! = firstInt gives a compilation error This expression was expected to have type Async<'a> but here has type IConnectableObservable<int> , so, apparently, C # does something under the hood that F # does not.
Is there a hidden C # interface when working here, what do I need to do explicitly in F #? If so, I cannot understand what it is.
source share