reactive-programming

Combining latest from an observable of observables

蓝咒 提交于 2019-12-10 11:26:55
问题 Suppose I have a set of URIs that I am monitoring for availability. Each URI is either "up" or "down", and new URIs to monitor may be added to the system at any time: public enum ConnectionStatus { Up, Down } public class WebsiteStatus { public string Uri { get; set; } public ConnectionStatus Status { get; set; } } public class Program { static void Main(string[] args) { var statusStream = new Subject<WebsiteStatus>(); Test(statusStream); Console.WriteLine("Done"); Console.ReadKey(); }

A build function returned null The offending widget is: StreamBuilder<Response>

孤人 提交于 2019-12-10 10:29:38
问题 I'm new to Flutter and I'm trying to accomplish a simple thing: I want to create a signup functionality using BLoC pattern and streams. For the UI part I have a stepper, that on the very last step should fire a request to the server with the collected data. I believe I have everything working until the StreamBuilder part. StreamBuilders are meant to return Widgets, however, in my case I don't need any widgets returned, if it's a success I want to navigate to the next screen, otherwise an

How to use Reactive Extensions to parse a stream of characters from a serial port?

馋奶兔 提交于 2019-12-10 03:41:56
问题 I need to parse a stream of serial data coming from a test instrument, and this seems to be an excellent application for Reactive Extensions. The protocol is very simple...each "packet" is a single letter followed by numeric digits. The number of numeric digits is fixed for each packet type, but can vary between packet types. e.g. ...A1234B123456C12... I am trying to break this up into an Observable of Strings, e.g. "A1234" "B123456" "C12" ... Thought this would be simple, but don't see the

Rx - Divide stream into segments (lists) by condition

送分小仙女□ 提交于 2019-12-10 03:21:19
问题 I have an RX producer that creates a stream of strings like so (simplified version of the real stream): A1 A2 A3 B1 B2 C1 C2 C3 C4 C5 C6.... The stream is endless, but ordered. So after the strings that start with A run out, B starts. When B runs out, C starts... when Z run out, we move to AA1 etc. There's an unknown number of A 's, B 's etc, but it's typically 10-30 instances per letter. I'm looking for a way to divide this stream into blocks of all A's: A1 A2 A3 , all B's: B1 B2 , all C's:

Catch error if retryWhen:s retries runs out

帅比萌擦擦* 提交于 2019-12-10 00:53:28
问题 In the documentation for RetryWhen the example there goes like this: Observable.create((Subscriber<? super String> s) -> { System.out.println("subscribing"); s.onError(new RuntimeException("always fails")); }).retryWhen(attempts -> { return attempts.zipWith(Observable.range(1, 3), (n, i) -> i).flatMap(i -> { System.out.println("delay retry by " + i + " second(s)"); return Observable.timer(i, TimeUnit.SECONDS); }); }).toBlocking().forEach(System.out::println); But how do I propagate the Error

Reactive Framework / DoubleClick

江枫思渺然 提交于 2019-12-09 19:31:08
问题 I know that there is an easy way to do this - but it has beaten me tonight ... I want to know if two events occur within 300 milliseconds of each other, as in a double click. Two leftdown mouse clicks in 300 milliseconds - I know this is what the reactive framework was built for - but damn if I can find a good doc that has simple examples for all the extenstion operatores - Throttle, BufferWithCount, BufferWithTime - all of which just werent' doing it for me.... 回答1: The TimeInterval method

how to calculate moving average in RxJava

浪尽此生 提交于 2019-12-09 17:21:19
问题 In finance domain, we usually need to calculate the moving-window aggregate value from a stream of time series data, use moving average as an example, say we have the following data stream(T is time stamp and V is the actual vlaue): [T0,V0],[T1,V1],[T2,V2],[T3,V3],[T4,V4],[T5,V5],[T6,V6],[T7,V7],[T8,V8],[T9,V9],[T10,1V0],...... to calculate a moving average 3 from the stream we get: avg([T0,V0],[T1,V1],[T2,V2]), avg([T1,V1],[T2,V2],[T3,V3]), avg([T2,V2],[T3,V3],[T4,V4]), avg([T3,V3],[T4,V4],

How to request data sequentially in Cycle.js?

拥有回忆 提交于 2019-12-09 16:08:07
问题 I’m new to reactive programming and toying around with cycle.js, trying to implement who to follow box from this tutorial. But I understood that for proper implementation (and learning purposes) I don’t have one piece of data: full user name. I can get it by sequentially getting users and then full user data from server. In imperative style I would do something like this: fetch(`https://api.github.com/users`) .then(data => data.json()) .then(users => fetch(users[0].url)) .then(data => data

RxJava, one observable multiple subscribers: publish().autoConnect()

≡放荡痞女 提交于 2019-12-09 14:29:14
问题 I'm playing around with rxJava/rxAndroid and there's something very basic that doesn't behave as I'd expect. I have this one observable and two subscribers: Observable<Integer> dataStream = Observable.just(1, 2, 3).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()); Log.d(TAG, "subscribing sub1..."); dataStream.subscribe(v -> System.out.println("Subscriber #1: "+ integer)); Log.d(TAG, "subscribing sub2..."); dataStream.subscribe(v -> System.out.println("Subscriber #2: "+

Flux not subscribing in Spring 5 reactor

ぐ巨炮叔叔 提交于 2019-12-09 13:26:53
问题 I'm probably missing something but I can't figure out what it is. The following code does nothing at all: webClient.get().uri("/some/path/here").retrieve() .bodyToMono(GetLocationsResponse.class) .doOnNext(System.out::println) .subscribe(); If I try to block the call it works fine: webClient.get().uri("/some/path/here").retrieve() .bodyToMono(GetLocationsResponse.class) .doOnNext(System.out::println) .block(); The weird thing is that if I create a Flux "manually" (i.e not coming from the