Skip to content
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

Observable.OfAsync now fires OnCompleted #835

Merged
merged 1 commit into from
May 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions src/Paket.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -399,22 +399,28 @@ module ObservableExtensions =
evt.Publish |> guard (fun o ->
for n in s do evt.Trigger(n))

let ofAsync a: IObservable<'a> =
{ new IObservable<'a> with
member __.Subscribe obs =
let token = new CancellationTokenSource()
Async.StartWithContinuations(a, obs.OnNext, obs.OnError, obs.OnError, token.Token)
{ new IDisposable with
member __.Dispose() =
token.Cancel |> ignore
token.Dispose() }}

let ofAsyncWithToken (token:CancellationToken) a: IObservable<'a> =
{ new IObservable<'a> with
member __.Subscribe obs =
Async.StartWithContinuations(a, obs.OnNext, obs.OnError, obs.OnError, token)
{ new IDisposable with
member __.Dispose() = () }}
let private oneAndDone (obs : IObserver<_>) value =
obs.OnNext value
obs.OnCompleted()

let ofAsync a : IObservable<'a> =
{ new IObservable<'a> with
member __.Subscribe obs =
let oneAndDone' = oneAndDone obs
let token = new CancellationTokenSource()
Async.StartWithContinuations(a,oneAndDone',obs.OnError,obs.OnError,token.Token)
{ new IDisposable with
member __.Dispose() =
token.Cancel |> ignore
token.Dispose() } }

let ofAsyncWithToken (token : CancellationToken) a : IObservable<'a> =
{ new IObservable<'a> with
member __.Subscribe obs =
let oneAndDone' = oneAndDone obs
Async.StartWithContinuations(a,oneAndDone',obs.OnError,obs.OnError,token)
{ new IDisposable with
member __.Dispose() = () } }

let flatten (a: IObservable<#seq<'a>>): IObservable<'a> =
{ new IObservable<'a> with
Expand Down