reactive-programming

How to emit cumulative sum only from a reactive stream?

孤街浪徒 提交于 2020-08-10 19:57:27
问题 I've a use case where the stream should only emit when the cumulative "sum" equals or exceeds a given value, n. Let's take the example of six integers with n = 5. +---+------+---------+ | i | Emit | Sum | +---+------+---------+ | 1 | - | 1 | | 2 | - | 3 | | 3 | 5 | 1 | | 4 | 5 | 0 | | 5 | 5 | 0 | | 2 | 2 | 0 (end) | +---+------+---------+ As you can see, nothing is emitted unless the sum equals or exceeds 5, except for the last element, which is emitted anyway. Once an item is emitted, the

Reactive Programming: Spring WebFlux: How to build a chain of micro-service calls?

对着背影说爱祢 提交于 2020-08-05 10:23:11
问题 Spring Boot Application: a @RestController receives the following payload: { "cartoon": "The Little Mermaid", "characterNames": ["Ariel", "Prince Eric", "Sebastian", "Flounder"] } I need to process it in the following way: Get the unique Id for each character name: make an HTTP call to "cartoon-characters" microservice, that returns ids by names Transform data received by the controller: replace character names with appropriate ids that were received on the previous step from "cartoon

RxjS shareReplay : how to reset its value?

社会主义新天地 提交于 2020-08-02 07:34:09
问题 I use shareReplay to call only once (like a cache) a webservice to retrieve some informations : In my service : getProfile(): Observable<Customer> { return this.callWS().pipe(shareReplay(1)); } In multiple components : this.myService.getProfile().subscribe(customer => { console.log('customer informations has been retrieved from WS :', customer); }); Now I want to add a method to force refresh the informations (bypass shareReplay only once). I tried with storing my observable in a variable,

Throttling in Swift without going reactive

馋奶兔 提交于 2020-07-05 13:51:30
问题 Is there a simple way of implementing the Throttle feature in Reactive programming without having to use RxSwift or similar frameworks. I have a textField delegate method that I would like not to fire every time a character is inserted/deleted. How to do that using vanilla Foundation? 回答1: Yes it is possible to achieve. But first lets answer small question what is Throttling? In software, a throttling process, or a throttling controller as it is sometimes called, is a process responsible for

who calls subscribe on Flux or Mono in reactive webapplication

喜欢而已 提交于 2020-06-22 03:19:10
问题 I am looking at some examples of reactive web applications and i am seeing them like this @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public Mono<Person> findById(...) { return exampleService.findById(...); } @RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_EVENT_STREAM_VALUE) @ResponseBody public Flux<Person> findAll() { Flux<Person> persons = exampleService.findAll(); return persons; } When i am reading about the Mono and Flux in the