reactive-programming

RxJava - How to stop (and resume) a Hot Observable (interval)?

假如想象 提交于 2019-12-05 12:56:42
I have the following Hot Observable: hotObservable = Observable.interval(0L, 1L, TimeUnit.SECONDS) .map((t) -> getCurrentTimeInMillis())) However, I can't find a good way to stop it. I was able to partially solve this using takeWhile and a boolean flag ( runTimer ): Observable.interval(0L, 1L, TimeUnit.SECONDS) .takeWhile((t) -> runTimer) .map((t) -> getCurrentTimeInMillis())) There are 2 things I don't like in this approach though: I must keep the flag runTimer around, which I don't want. Once runTimer becomes false , the Observable simply completes, which means if I want to emit again I need

Reactive Extensions swallows exceptions from OnNext() called on a thread pool thread?

 ̄綄美尐妖づ 提交于 2019-12-05 12:38:23
I use Rx 2 in .Net 4.5. When the following code runs, it just exits silently without executing the OnCompleted delegate or showing any errors. If I use Scheduler.CurrentThread in ToObservable , it will at least throw the error and terminate the program, at which point not executing OnCompleted makes sense. But when this is executed in a thread other than the main one, this behavior seems unreasonable and unacceptable. Do I miss anything? static void Main() { Enumerable.Range(0, 1) .ToObservable(Scheduler.Default) .Subscribe(o => { throw new Exception("blah"); }, () => Console.WriteLine(

Spring 5 Web Reactive - Hot Publishing - How to use EmitterProcessor to bridge a MessageListener to an event stream

ぃ、小莉子 提交于 2019-12-05 11:08:59
A sample project is located here: https://github.com/codependent/spring5-playground I would like to bridge a message received from a JMS queue into a Reactive Controller that would publish the messages as an event stream. I don't want the messages to be replayed, that is, if a message arrives and there isn't any subscriber I don't want them to be sent later when any subsbribes, so I am using an EmitterProcessor: @Component public class AlertEmitterProcessor { private Logger logger = LoggerFactory.getLogger(getClass()); private EmitterProcessor<Alert> processor; public AlertEmitterProcessor(){

What is difference between two way data binding and reactivity?

旧时模样 提交于 2019-12-05 10:53:30
As i follow some tuts for angular and ember.js I came across the term Two way data binding. Where data displayed on UI are bind with database and any changes to one is quickly propagated to the other. When I started learning meteor.js i came across term "Reactivity" which for me makes same sense as two way data binding. Can you please tell me fundamental difference between these two terms? Reactivity is in fact more general than data binding. With reactivity you can implement data binding, in a really simple way, e.g. var myAwesomeData = "some data"; var myAwseomeDependency = new Tracker

Synchronous stream of responses from a stream of requests with RxJS

爱⌒轻易说出口 提交于 2019-12-05 10:33:52
I'm new to RxJS and was wondering if anyone could help me. I want to create a synchronous stream of responses (preferably with the corresponding requests) from a stream of requests(payload data). I basically want the requests to be sent one by one, each waiting for the response from the last one. I tried this, but it sends everything at once ( jsbin ): var requestStream, responseStream; requestStream = Rx.Observable.from(['a','b','c','d','e']); responseStream = requestStream.flatMap( sendRequest, (val, response)=>{ return {val, response}; } ); responseStream.subscribe( item=>{ console.log(item

What is the MutableLiveData equivalent in RxJava?

被刻印的时光 ゝ 提交于 2019-12-05 10:31:40
Per the example below from the LiveData Android documentation, what would be the RxJava 2 equivalent? We certainly can use a combination of publish() , refcount() and replay() to achieve the core of the MutableLiveData observable behavior. That said, what would be the analogous counterpart of mCurrentName.setValue() as it pertains to detecting a change and emitting the corresponding event? public class NameViewModel extends ViewModel { // Create a LiveData with a String private MutableLiveData<String> mCurrentName; public MutableLiveData<String> getCurrentName() { if (mCurrentName == null) {

Reactive Extensions Parallel processing based on specific number

只愿长相守 提交于 2019-12-05 09:25:38
问题 I'm new to Reactive Extensions. I have objects collection and call a method for each object and method returns Boolean. Instead of looping through each by using for each loop and calling the method, is there a way in reactive extensions to call concurrently(fork and join) the method for a given number of objects(ex 5 at a time) and after first one done, 6th one should call method and it should continue until all the objects are done. I appreciate your response. 回答1: IObservable<bool>

RxJS - observable doesn't complete when an error occurs

萝らか妹 提交于 2019-12-05 08:21:10
问题 When I create an observable from scratch, and have the observer error, then complete, the done part of the subscription never is invoked. var observer = Rx.Observable.create(function(observer){ observer.onError(new Error('no!')); observer.onCompleted(); }) observer.subscribe( function(x) { console.log('succeeded with ' + x ) }, function(x) { console.log('errored with ' + x ) }, function() { console.log('completed') } ) The output is: errored with Error: no! I'd expect it to be: errored with

Execute Future.sequence with custom ExecutionContext

☆樱花仙子☆ 提交于 2019-12-05 08:03:22
I'm trying to create a Future[List[Int]] from a List[Future[Int]] using a specified ExecutionContext . However, I'm getting errors about a second implicit parameter cbf of type CanBuildFrom . I don't fully understand the purpose of the CanBuildFrom parameter, and I'm getting errors when I try to omit it that look like the following: - not enough arguments for method sequence: (implicit cbf: scala.collection.generic.CanBuildFrom[List[scala.concurrent.Future[Int]],Int,List[Int]] Can someone explain this, and suggest a solution? Here is my current test code, which suffers the above compilation

Debounce without initial delay

丶灬走出姿态 提交于 2019-12-05 06:39:37
Is there an operator in RxJS that debounces without delaying the "first event in a burst", but delaying (and always emitting) the "last event in a burst"? Something like this: ---a----b-c-d-----e-f--- after awesome-debounce(2 dashes) becomes: ---a----b------d--e----f while a normal debounce would be: -----a---------d-------f It's kind of a mix between throttle and debounce... martin Hmmm, this is the easiest solution I can think of. The interesting part for you is the awesomeDebounce() function that creates the sub-chain. It basically just combines throttle() and debounceTime() operators: