reactive-programming

Howto call back async function from rx subscribe?

匆匆过客 提交于 2019-11-28 05:27:06
I would like to call back an async function within an Rx subscription. E.g. like that: public class Consumer { private readonly Service _service = new Service(); public ReplaySubject<string> Results = new ReplaySubject<string>(); public void Trigger() { Observable.Timer(TimeSpan.FromMilliseconds(100)).Subscribe(async _ => await RunAsync()); } public Task RunAsync() { return _service.DoAsync(); } } public class Service { public async Task<string> DoAsync() { return await Task.Run(() => Do()); } private static string Do() { Thread.Sleep(TimeSpan.FromMilliseconds(200)); throw new

Implementing a turnstile-like operator with RxJava

十年热恋 提交于 2019-11-28 05:09:23
问题 I need help implementing a turnstile-like operator in RxJava (RxScala). I spent quite some time thinking about it, but I seem to be stuck. The type of the function should be the following: def turnstile[T](queue: Observable[T], turnstile: Observable[Boolean]): Observable[T] The idea is that the behavior of the operator should be very similar to a real turnstile. There are people coming ( queue ), and there is a turnstile that is either ready for accepting new single person (a true element in

block()/blockFirst()/blockLast() are blocking error when calling bodyToMono AFTER exchange()

僤鯓⒐⒋嵵緔 提交于 2019-11-28 05:02:56
问题 I am trying to use Webflux to stream a generated file to another location, however, if the generation of the file ran into an error, the api returns success, but with a DTO detailing the errors while generating the file instead of the file itself. This is using a very old and poorly designed api so please excuse the use of post and the api design. The response from the api call (exchange()) is a ClientResponse. From here I can either convert to a ByteArrayResource using bodyToMono which can

Creating Observable without using Observable.create

倖福魔咒の 提交于 2019-11-28 04:55:23
I am using RxJava in my Android app and I want to load data from the database. In this way, I am creating a new Observable using Observable.create() which returns a list of EventLog public Observable<List<EventLog>> loadEventLogs() { return Observable.create(new Observable.OnSubscribe<List<EventLog>>() { @Override public void call(Subscriber<? super List<EventLog>> subscriber) { List<DBEventLog> logs = new Select().from(DBEventLog.class).execute(); List<EventLog> eventLogs = new ArrayList<>(logs.size()); for (int i = 0; i < logs.size(); i++) { eventLogs.add(new EventLog(logs.get(i))); }

How do I rate limit requests losslessly using RxJS 5

≡放荡痞女 提交于 2019-11-28 04:11:30
问题 I would like to use make a series of requests to a server, but the server has a hard rate limit of 10 request per second. If I try to make the requests in a loop, it will hit the rate limit since all the requests will happen at the same time. for(let i = 0; i < 20; i++) { sendRequest(); } ReactiveX has lots of tools for modifying observable streams, but I can't seem to find the tools to implement rate limiting. I tried adding a standard delay, but the requests still fire at the same time,

How to create an Observable from OnClick Event Android?

∥☆過路亽.° 提交于 2019-11-28 03:40:56
I'm new in reactive programming. So I have problem when create a stream from an Event, like onClick, ontouch... Can anyone help me solve this problem. Thanks. Miguel Lavigne You would do something like this: Observable<View> clickEventObservable = Observable.create(new Observable.OnSubscribe<View>() { @Override public void call(final Subscriber<? super View> subscriber) { viewIWantToMonitorForClickEvents.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (subscriber.isUnsubscribed()) return; subscriber.onNext(v); } }); } }); // You can then apply all

RxJs: How to loop based on state of the observable?

核能气质少年 提交于 2019-11-28 03:32:23
问题 I'm trying to get RxJs to loop over an Observable in my stream until it is in a certain state, then have the stream continue. Specifically I'm converting a synchronous do/while loop to RxJs, but I assume the same answer could be used for a for or while loop as well. I thought I could use doWhile() for this, but it seems like the condition function does not have access to the item in the stream, which seems to defeat the purpose to me. I'm not completely sure what the correct reactive

What's the status of current Functional Reactive Programming implementations?

做~自己de王妃 提交于 2019-11-28 02:46:49
I'm trying to visualize some simple automatic physical systems (such things as pendulum, robot arms,etc.) in Haskell. Often those systems can be described by equations like df/dt = c*f(t) + u(t) where u(t) represents some kind of 'intelligent control'. Those systems look to fit very nicely in the Functional Reactive Programming paradigm. So I grabbed the book "The Haskell School of Expression" by Paul Hudak, and found that the domain specific language "FAL" (for Functional Animation Language) presented there actually works quite pleasently for my simple toy systems (although some functions,

Rxjs - How can I extract multiple values inside an array and feed them back to the observable stream synchronously

巧了我就是萌 提交于 2019-11-28 01:20:16
问题 I have created a Rx.Observable from a stream of events: Rx.Observable.fromEvent(recognizeStream, 'data') In which every data event looks like this: { error: null, alternatives: [result1, result2, result3] } I want to pluck every value inside the array of alternatives and merge those into the stream. What operators do I have to look at? As far as I know the flatMap and concatMap could do the job but I don't get the idea from their example. Can somebody explain which operator i should use and

In Shiny apps for R, how do I delay the firing of a reactive?

二次信任 提交于 2019-11-28 00:41:50
问题 I have a selectizeInput in my Shiny app. It is in multiple-select mode, so the user can specify more than one selection. However, the reactives that depend on the selectizeInput get fired every time a selection is added. Suppose that the user intends to select A , B and C . Currently, my app will do it expensive computations for the selections A , A, B and A, B, C , when only the last is required. The best way I can think to solve this is to delay the firing of the selectizeInput by a second