reactive-programming

who calls subscribe on Flux or Mono in reactive webapplication

ε祈祈猫儿з 提交于 2020-06-22 03:19:07
问题 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

How to create a custom chain in Swift Combine?

自作多情 提交于 2020-06-17 15:56:05
问题 I'm trying to create a LocationManager wrapper for Combine. I have a publisher and some functions that trigger the publisher. However, I'd like to combine them in one with a custom command. Here's what I got so far: @available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *) public class LocationProxy: NSObject { private lazy var manager = CLLocationManager() private static let authorizationSubject = PassthroughSubject<Bool, Never>() public private(set) lazy var authorizationPublisher: AnyPublisher

Parallel http requests via forkJoin and response identification

和自甴很熟 提交于 2020-06-16 17:01:11
问题 I would like to make parallel independent calls to an endpoint. First I construct my calls then I call forkJoin . getAllDirections(data: Object, date: string) { let urls = []; for (let elm in data) { let url = `http:XXXXX?date=${date}&directions=${data[elm].All.join()}`; urls.push(this.http.get<ISchedules>(url)); } return forkJoin(urls).pipe( map(dirData => { let dataSorted = dirData.map(elm => _.groupBy(elm.data, 'direction')); return dataSorted; }) ); } the data params is an objects of

Spring WebFlux - how to get data from DB to use in the next step

馋奶兔 提交于 2020-06-16 07:11:27
问题 I use Spring WebFlux (Project Reactor) and I'm facing the following problem: I have to get some data from db to use them to call another service - everything in one stream. How to do that? public Mono<MyObj> saveObj(Mono<MyObj> obj) { return obj .flatMap( ob-> Mono.zip( repo1.save( ...), repo2 .saveAll(...) .collectList(), repo3 .saveAll(...) .collectList()) .map(this::createSpecificObject)) .doOnNext(item-> createObjAndCallAnotherService(item)); } private void createObjAndCallAnotherService

Using onBlur with JSX and React

拈花ヽ惹草 提交于 2020-06-09 15:28:54
问题 I am trying to create a password confirmation feature that renders an error only after a user leaves the confirmation field. I'm working with Facebook's React JS. This is my input component: <input type="password" placeholder="Password (confirm)" valueLink={this.linkState('password2')} onBlur={this.renderPasswordConfirmError()} /> This is renderPasswordConfirmError : renderPasswordConfirmError: function() { if (this.state.password !== this.state.password2) { return ( <div> <label className=

Using onBlur with JSX and React

你。 提交于 2020-06-09 15:28:00
问题 I am trying to create a password confirmation feature that renders an error only after a user leaves the confirmation field. I'm working with Facebook's React JS. This is my input component: <input type="password" placeholder="Password (confirm)" valueLink={this.linkState('password2')} onBlur={this.renderPasswordConfirmError()} /> This is renderPasswordConfirmError : renderPasswordConfirmError: function() { if (this.state.password !== this.state.password2) { return ( <div> <label className=

Using onBlur with JSX and React

人盡茶涼 提交于 2020-06-09 15:27:51
问题 I am trying to create a password confirmation feature that renders an error only after a user leaves the confirmation field. I'm working with Facebook's React JS. This is my input component: <input type="password" placeholder="Password (confirm)" valueLink={this.linkState('password2')} onBlur={this.renderPasswordConfirmError()} /> This is renderPasswordConfirmError : renderPasswordConfirmError: function() { if (this.state.password !== this.state.password2) { return ( <div> <label className=

Calling methods in two different ReactiveMongoRepository's in a transaction using Spring Data MongoDB?

情到浓时终转凉″ 提交于 2020-06-07 06:00:32
问题 When using the reactive programming model with Spring Data MongoDB it's possible to execute transactions like this: Mono<DeleteResult> result = template.inTransaction() .execute(action -> action.remove(query(where("id").is("step-1")), Step.class)); But Spring Data MongoDB also has support for "reactive repositories", for example: public interface PersonRepository extends ReactiveMongoRepository<Person, String> Flux<Person> findByLocationNear(Point location, Distance distance); } and public

Merging unknown number of observables with RxJS

爷,独闯天下 提交于 2020-05-29 03:51:07
问题 I am currently triing to create a small project to demo Reactive Programming with RxJS. The goal is to show my colleagues that this thing is out there, and it is worth looking into. I'm not experienced with the framework, so that makes things complicated. I am triing to expand another demo of mine to utilize RxJS. It is not a very complicated demo, basically I can add any number of small forms, wich result in a number calculated by a small formula, and there is a button, wich sums up the

RxJava-file and operator chaining

好久不见. 提交于 2020-05-27 06:21:09
问题 I'm trying to reactively tail a log file using RxJava-File: File file = new File(".\\server.log"); Observable<String> newLines = FileObservable.tailer() .file(file) .startPosition(file.length()) .sampleTimeMs(1000) .chunkSize(8192) .utf8() .tailText(); newLines.subscribe(System.out::println); and it works as expected. But as soon as I try to chain some more operators, I get problems. For instance, changing to newLines.filter(LogfileWatcher::error).subscribe(System.out::println); (where error(