system.reactive

How to use the new BufferWithTimeOrCount in Rx that returns IObservable<IObservable<T>> instead of IObservable<IList<T>>

萝らか妹 提交于 2019-12-31 03:26:07
问题 On Windows Phone 7 there is a new version of the BufferWithTimeOrCount extension method for IObservable that returns a "stream of streams" instead of the previous "stream of lists". I'm having difficulty trying to use either the new or old methods, so maybe I just don't understand how it works, but my goal is to create a stream that only fires when an existing stream matches a specified time based pattern during the previous 2 touch events. So far I have created streams for TouchUp and

How to convert an IEnumerable<Task<T>> to IObservable<T>

你说的曾经没有我的故事 提交于 2019-12-30 17:26:23
问题 Is there a built in way to convert an IEnumerable<Task<T>> to an IObservable<T>. Order doesn't matter, just that I get things, though preferably as they're completed. If it doesn't exist yet, what might be a good way to accomplish it? 回答1: I believe this will work tasks.Select(t => Observable.FromAsync(() => t)) .Merge(); Each task will send its results to the observable sequence in whatever order they complete. You can subscribe to the sequence and do whatever you want with the results that

RxJS: MergeMap with Preserving Input order

二次信任 提交于 2019-12-30 11:21:51
问题 Requirement: urls = [url1, url2, url3] Fire all 3 urls parallely and paint the Dom in the sequnce of the urls list ex: Finished order of urls = [url3, url1, url2] when url1 finishes Immediately render the DOM, without waiting for url2 If url2, url3 finishes before url1, then store url2, url3 and paint the DOM after url1 arrives Paint the DOM with order [url1, url2, url3] My Work using promises: // Fired all 3 urls at the same time p1 = fetch(url1) p2 = fetch(url2) p3 = fetch(url3) p1.then

CombineLatest, but only push for the left

南楼画角 提交于 2019-12-30 08:35:10
问题 I need to implement a version of CombineLatest (I'll call it WithLatest here) that calls the selector for every item on the left and the latest item on the right. It shouldn't push for items on the right changing only. I think whether this is built Observable.Create or a combination of existing extensions is not particularly important; I'll be making this a "boxed" extension method either way. Example var left = new Subject<int>(); var right = new Subject<int>(); left.WithLatest(right, (l,r)

Is there a way to subscribe an observer as async

我怕爱的太早我们不能终老 提交于 2019-12-30 07:39:27
问题 Given a synchronous observer, is there a way to do this: observable.SubscribeAsync(observer); And have all methods on the observer called asynchronously or is that something I have to handle when creating the observer? 回答1: You might want to look into ObserveOn and SubscribeOn (more information and even more information). 回答2: If you need to call an async method when the stream spits out a new value, the most common solution you will find is to use SelectMany . The problem is that this doesn

Using Reactive Extensions (Rx) for socket programming practical?

我是研究僧i 提交于 2019-12-29 11:50:10
问题 What is the most succint way of writing the GetMessages function with Rx: static void Main() { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); var messages = GetMessages(socket, IPAddress.Loopback, 4000); messages.Subscribe(x => Console.WriteLine(x)); Console.ReadKey(); } static IObservable<string> GetMessages(Socket socket, IPAddress addr, int port) { var whenConnect = Observable.FromAsyncPattern<IPAddress, int>(socket.BeginConnect, socket

How to mock WCF client using Moq?

早过忘川 提交于 2019-12-28 16:13:08
问题 In my project I am using: SL5+ MVVM+ Prism + WCF + Rx + Moq + Silverlight Unit Testing Framework. I am new to unit-testing and have recently started into DI, Patterns (MVVM) etc. Hence the following code has a lot of scope for improvement (please fell free to reject the whole approach I am taking if you think so). To access my WCF services, I have created a factory class like below (again, it can be flawed, but please have a look): namespace SomeSolution { public class ServiceClientFactory

How to handle exceptions thrown by observer's onNext in RxJava?

爱⌒轻易说出口 提交于 2019-12-28 11:59:18
问题 Consider the following example: Observable.range(1, 10).subscribe(i -> { System.out.println(i); if (i == 5) { throw new RuntimeException("oops!"); } }, Throwable::printStackTrace); This outputs numbers from 1 to 5 and then prints the exception. What I want to achieve is make the observer stay subscribed and continue to run after throwing an exception, i.e. print all numbers from 1 to 10. I have tried using retry() and other various error handling operators, but, as said in the documentation,

NewThreadScheduler.Default schedules all work on same thread

岁酱吖の 提交于 2019-12-28 06:56:06
问题 I'm currently trying to wrap my head around concurrency with RX .NET and getting confused by something. I want to run four relatively slow tasks in parallel, so I assumed NewThreadScheduler.Default would be the way to go, as it "Represents an object that schedules each unit of work on a separate thread." . Here's my setup code: static void Test() { Console.WriteLine("Starting. Thread {0}", Thread.CurrentThread.ManagedThreadId); var query = Enumerable.Range(1, 4); var obsQuery = query

RxJava and parallel execution of observer code

社会主义新天地 提交于 2019-12-28 05:07:20
问题 I am having the following code using RxJava Observable api : Observable<Info> observable = fileProcessor.processFileObservable(processedFile.getAbsolutePath()); observable .buffer(10000) .observeOn(Schedulers.computation()) .subscribe(recordInfo -> { _logger.info("Running stage2 on thread with id : " + Thread.currentThread().getId()); for(Info info : recordInfo) { // some I/O operation logic } }, exception -> { }, () -> { }); My expectation was that the observation code i.e. code inside the