reactive-programming

Spring Reactive: java.io.IOException: An established connection was aborted by the software in your host machine, when I close the connection

匆匆过客 提交于 2019-12-24 08:25:42
问题 Working with spring reactive application, I created a rest service which produces an event every second. The code for my rest controller is: @GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE) public Flux<Event> getEvents() { Flux<Event> eventFlux = Flux.fromStream(Stream.generate(() -> new Event(new Random().nextLong(), "Hello Event"))); Flux<Long> emmitFlux = Flux.interval(Duration.ofSeconds(1)); return Flux.zip(eventFlux, emmitFlux).map(Tuple2::getT1); } The

Flatlist React Native - No Data Display

断了今生、忘了曾经 提交于 2019-12-24 08:23:48
问题 We are developing a react native application using Flatlist. Binding data from API service & its working fine. Suppose no data available in service we need to display separate design for that. We are using "renderEmptyListComponent" for that sharing the code, please check <FlatList style={{ backgroundColor: 'white' }} data={this.state.dataSource} renderItem={({ item }) => (this.renderMovie(item))} keyExtractor={item => item.salesID} renderEmptyListComponent= {this.noItemDisplay}

How to build a reactive pipeline with different Publishers without losing data?

浪尽此生 提交于 2019-12-24 06:46:27
问题 Imagine you have code like this: public List<Group> addUserToGroups(String username, String label) { Mono<User> userMono = webClient.getUser(username); User user = userMono.block(); Flux<Group> groupsFlux = webClient.getGroups(label); List<Group> groups = groupsFlux.collectList().block(); groups.forEach(group -> webClient.addUserToGroup(user.getId(), group.getId()).block() ); return groups; } But now you want to refactor this code into a non-blocking reactive pipeline, and the main method to

Running a simple Scala.React expression

久未见 提交于 2019-12-24 03:51:42
问题 I am looking into Scala.React, and the updated paper on the issue, trying to get a simple Signal based example to work. I understand that the Signal method in the paper doesn't exist as such, but instead there are Strict and Lazy . So my naive first attempt: Setting up the whole thing: object dom extends scala.react.Domain { val engine = new Engine val scheduler = new ManualScheduler } import dom._ Trying out composition: val v1, v2 = Var(0) val f = Strict { v1() + v2() } The second line

Should I use akka.http.scaladsl.util.FastFuture instead of scala.concurrent.Future?

房东的猫 提交于 2019-12-24 02:25:12
问题 Should I use akka.http.scaladsl.util.FastFuture instead of scala.concurrent.Future? The comment says : /** * Provides alternative implementations of the basic transformation operations defined on [[scala.concurrent.Future]], * which try to avoid scheduling to an [[scala.concurrent.ExecutionContext]] if possible, i.e. if the given future * value is already present. */ Do I get any performance improvement especially when I need to use Future.apply , Future.successful or Future.failed ? What

RxJava. Read file to observable

那年仲夏 提交于 2019-12-24 01:31:48
问题 I am totally new to RxJava and reactive programming. I have an assignment where i must read file and store it to Observable. I have tried to make a Callable with BufferedReader inside and use Observable.fromCallable(), but it didn't work much. Could you please show me how can i do that? I am using RxJava 2.0. 回答1: A basic solution where I use a nested class FileObservableSource to produce the data and then defer the creation of the Observable until an Observer subscribes: import io.reactivex

How to call on_error on a custom rxcpp operator

雨燕双飞 提交于 2019-12-24 00:46:44
问题 I've created a simple rx operator that converts a stream of strings to a stream of jsons and it works fine. However, I would like to be able to raise a custom exception and I am not sure how to call the on_error method of the subscription The operator is called convertStringToJson and a working sample can be found here: https://github.com/cipriancaba/rxcpp-examples/blob/master/src/SimpleOperators.cpp function<observable<json>(observable<string>)> SimpleOperators::convertFromStringToJson() {

Cancel RX.Net Observer's ongoing OnNext methods

时光总嘲笑我的痴心妄想 提交于 2019-12-24 00:29:13
问题 As described in my original question (see Correlate interdependent Event Streams with RX.Net) I have an RX.net event stream that shall only call the observer's OnNext method as long as a certain other event is not triggered (basically 'Handle Change-* Events as long as the system is connected, pause while disconnected and re-start handling of the Change-* events once the system has re-connected). However, while this works smoothly with new events, how would I cancel / signal cancellation to

Is there an more ideomatic way to split a stream by some predicate?

非 Y 不嫁゛ 提交于 2019-12-24 00:17:52
问题 I have a stream of events, which I want to split into multiple streams, based on some property the event may have. Something like the following let streams = new rx.Subject() let stream = new rx.Subject() input.subscribe((x) => { stream.onNext(x) if (!x.splitHere) return streams.onNext(stream) stream = new rx.Subject() }) EDIT Thank you for the hints about partition and if . While they do split one stream into multiple, they only provide two result streams. Clarification What I need to do is

Downlolad and save file from ClientRequest using ExchangeFunction in Project Reactor

给你一囗甜甜゛ 提交于 2019-12-23 19:36:50
问题 I have problem with correctly saving a file after its download is complete in Project Reactor. class HttpImageClientDownloader implements ImageClientDownloader { private final ExchangeFunction exchangeFunction; HttpImageClientDownloader() { this.exchangeFunction = ExchangeFunctions.create(new ReactorClientHttpConnector()); } @Override public Mono<File> downloadImage(String url, Path destination) { ClientRequest clientRequest = ClientRequest.create(HttpMethod.GET, URI.create(url)).build();