public virtual async Task <ContinuousChangesResponse> GetAsync(GetChangesRequest request, Action <string> onRead, CancellationToken cancellationToken) { var httpRequest = ContinuousHttpRequestFactory.Create(request); using (var httpResponse = await SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ForAwait()) { var response = ContinuousChangesResponseFactory.Create(httpResponse); if (response.IsSuccess) { using (var content = await httpResponse.Content.ReadAsStreamAsync().ForAwait()) { using (var reader = new StreamReader(content, MyCouchRuntime.DefaultEncoding)) { while (!cancellationToken.IsCancellationRequested && !reader.EndOfStream) { //cancellationToken.ThrowIfCancellationRequested(); if (!cancellationToken.IsCancellationRequested) { onRead(reader.ReadLine()); } } } } } return(response); } }
public virtual IObservable <string> ObserveContinuous(GetChangesRequest request, CancellationToken cancellationToken) { EnsureContinuousFeedIsRequested(request); return(Observable.Create <string>(async o => { var httpRequest = ContinuousHttpRequestFactory.Create(request); using (var httpResponse = await SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ForAwait()) { var response = ContinuousChangesResponseFactory.Create(httpResponse); if (response.IsSuccess) { using (var content = await httpResponse.Content.ReadAsStreamAsync().ForAwait()) { using (var reader = new StreamReader(content, MyCouchRuntime.DefaultEncoding)) { while (!cancellationToken.IsCancellationRequested && !reader.EndOfStream) { //cancellationToken.ThrowIfCancellationRequested(); if (!cancellationToken.IsCancellationRequested) { o.OnNext(reader.ReadLine()); } } } } } o.OnCompleted(); return Disposable.Empty; } }).SubscribeOn(ObservableSubscribeOnScheduler())); }
public virtual IObservable <string> ObserveContinuous(GetChangesRequest request, CancellationToken cancellationToken) { var httpRequest = ContinuousHttpRequestFactory.Create(request); var ob = new MyObservable <string>(); Task.Factory.StartNew(async() => { using (var httpResponse = await SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ForAwait()) { var response = await ContinuousChangesResponseFactory.CreateAsync(httpResponse).ForAwait(); if (response.IsSuccess) { using (var content = await httpResponse.Content.ReadAsStreamAsync().ForAwait()) { using (var reader = new StreamReader(content, MyCouchRuntime.DefaultEncoding)) { while (!cancellationToken.IsCancellationRequested && !reader.EndOfStream) { //cancellationToken.ThrowIfCancellationRequested(); if (!cancellationToken.IsCancellationRequested) { ob.Notify(reader.ReadLine()); } } ob.Complete(); } } } } }, cancellationToken).ForAwait(); return(ob); }