reactive-programming


Combining groupBy and flatMap(maxConcurrent, …) in RxJava/RxScala

允我心安 提交于 2020-01-17 07:29:49
问题 I have incoming processing requests, of which I want do not want too many processing concurrently due to depleting shared resources. I also would prefer requests which share some unique key to not be executed concurrently: def process(request: Request): Observable[Answer] = ??? requestsStream .groupBy(request => request.key) .flatMap(maxConcurrentProcessing, { case (key, requestsForKey) => requestsForKey .flatMap(1, process) }) However, the above doesn't work because the observable per key

How to run mono in the same thread, inside parallel flux

与世无争的帅哥 提交于 2020-01-16 08:38:12
问题 I'm trying to fill objects inside Flux with values from Mono. When i'm trying to do so, it's just ignoring my "set" operation. I assume that it's because Flux is working in parallel, while Mono is not. How can i solve this problem? Flux.fromIterable(proxyParserService.getProxyList()) .parallel() .runOn(Schedulers.parallel()) .filter(proxy -> proxy.getCorrupted() == null || !proxy.getCorrupted()) .subscribe(proxy -> { try { RestTemplate restTemplate = getProxiedTemplate(proxy.getHost(), proxy

Isolate reactivity in an ordered list

匆匆过客 提交于 2020-01-16 01:08:32
问题 I have got a template that shows tiles in a particular order: <template name="container"> {{#each tiles}}{{>tile}}{{/each}} </template> Now the container is a list of tiles that is stored as an array in mongodb. Since I want the tiles to be shown in the same order as they appear in that array, I'm using the following helper: Template.container.tiles = function () { return _.map(this.tiles || [], function(tileId) { return _.extend({ container: this }, Tiles.findOne({_id: tileId})); }, this); }

How to get these shinyApp parameters to be “reactive” to input changes

╄→гoц情女王★ 提交于 2020-01-15 09:24:18
问题 I'm building a simple shinyApp that plots a normal distribution given two quantiles (lbv and ubv) corresponding to 5% and 95% probability (a 90% confidence interval). The quantiles are user-defined inputs. To get the mean and sd of the normal PDF, I'm using get.norm.par() from the rriskDistributions package, like so: dpar <- get.norm.par(p=c(0.05,0.95),q=c(lbv,ubv),plot=F) mean <- dpar[1] sd <- dpar[2] How do I get the shinyApp to react to input changes in the UI? I'm new to Shiny - it seems

Combining 'n' Observables of the same type (RxJava)

时光怂恿深爱的人放手 提交于 2020-01-15 07:46:37
问题 I have a code flow that generates an Iterable of Observables of the same type. I then go through them all, combining them and returning the result as an Observable. At the moment I'm using zip with a FuncN, which seems horrible and I think I've missed the point somewhere. Here's an example that uses a Map, it's obviously nonsense but you get the idea. final ImmutableList.Builder<Map<String, Object>> observables = ImmutableList.builder(); for (String key: keys) { if (someTest(key)) {

The most efficient way to split a Flux to multiple Fluxes in Reactor 3

徘徊边缘 提交于 2020-01-15 07:30:12
问题 In Reactor 3, what's the most efficient way to split a heterogeneous flux to multiple fluxes by pattern matching? (And subsequent operations on each flux may be very different) For example, Source Flux: a->b->c->a->b->c || vv A Flux: a->a->a B Flux: b->b->b C Flux: c->c->c I'm new to reactive programming, and the only solution I come up with is share() + filter() , like val shared = flux.share(); shared.filter(x -> x.tag=='a').subscribe(a -> consumeA(a)); shared.filter(x -> x.tag=='b')

C# reactive extensions what happens when OnNext take long time and observable producing new events

风流意气都作罢 提交于 2020-01-15 05:28:08
问题 I'm new to Rx and I'm thinking what happens when IObservable is producing lot of events very quickly and OnNext take very long time. I guess that new events are queued somehow internally so I can possible run our memory. Am I right? Consider following small example: Subject<int> subject = new Subject<int>(); subject.ObserveOn(Scheduler.ThreadPool).Subscribe(x => { Console.WriteLine("Value published: {0}", x); Thread.Sleep(100); }, () => Console.WriteLine("Sequence Completed.")); for (int i =

Take first elements of stream after previous element matches condition

核能气质少年 提交于 2020-01-15 03:31:05
问题 I'm new to reactive extensions (rx) and try to do the following thing in .NET (but should be the same in JS and other languages.): I have a stream incoming with objects containing a string and a bool property. The stream would be infinite. I have the following conditions: The first object should always be printed. Now all incoming objects should be skipped until an object arrives with the bool property set to "true". When an object arrives with the bool property set to "true", this object

How to use Micrometer Timer to record duration of async method (returns Mono or Flux)

折月煮酒 提交于 2020-01-14 10:13:28
问题 I'd like to use Micrometer to record the execution time of an async method when it eventually happens. Is there a recommended way to do this? Example: Kafka Replying Template. I want to record the time it takes to actually execute the sendAndReceive call (sends a message on a request topic and receives a response on a reply topic). public Mono<String> sendRequest(Mono<String> request) { return request .map(r -> new ProducerRecord<String, String>(requestsTopic, r)) .map(pr -> { pr.headers()

How to use Micrometer Timer to record duration of async method (returns Mono or Flux)

做~自己de王妃 提交于 2020-01-14 10:11:18
问题 I'd like to use Micrometer to record the execution time of an async method when it eventually happens. Is there a recommended way to do this? Example: Kafka Replying Template. I want to record the time it takes to actually execute the sendAndReceive call (sends a message on a request topic and receives a response on a reply topic). public Mono<String> sendRequest(Mono<String> request) { return request .map(r -> new ProducerRecord<String, String>(requestsTopic, r)) .map(pr -> { pr.headers()

工具导航Map