reactive-programming

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

大憨熊 提交于 2019-12-05 00:02:37
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: "+ integer)); And this is the output: D/RxJava: subscribing sub1... D/RxJava: subscribing sub2... D/RxJava:

Testing in reactive-banana

青春壹個敷衍的年華 提交于 2019-12-04 23:48:11
问题 Is there a way to unit test networks created in reactive banana? Say I've built up some network with some input events - is it possible to verify that events have produced some output stream/behaviours have some value after some number of input events. Does it even make sense to do this? I noticed there are various interpret* functions but couldn't seem to work out how to use them. There's also the Model module which looks ideal for testing but has completely different types to the real

How to make countdown timer with RxJS Observables?

安稳与你 提交于 2019-12-04 23:39:52
I'm struggling to create a countdown timer using Observables, the examples at http://reactivex.io/documentation/operators/timer.html do not seem to work. In this specific example the error related to timerInterval not being a function of the Observable returned from timer. I have also been experimenting with other approaches and the best I've come up with is: Observable.interval(1000).take(10).subscribe(x => console.log(x)); The problem here is it counts up from 0 to 10 and I want a countdown timer e.g. 10,9,8...0. I've also tried this but the timer does not exist for type Observable

RxJS distinctUntilChanged - object comparsion

此生再无相见时 提交于 2019-12-04 22:44:07
I have stream of objects and I need to compare if current object is not same as previous and in this case emit new value. I found distinctUntilChanged operator should do exactly what I want, but for some reason, it never emit value except first one. If i remove distinctUntilChanged values are emited normally. My code: export class SettingsPage { static get parameters() { return [[NavController], [UserProvider]]; } constructor(nav, user) { this.nav = nav; this._user = user; this.typeChangeStream = new Subject(); this.notifications = {}; } ngOnInit() { this.typeChangeStream .map(x => {console

Keyboard shortcuts to trigger reactive flows in R Shiny?

穿精又带淫゛_ 提交于 2019-12-04 21:34:20
Is it possible to have, say, F7 or Q trigger a reactive flow in a Shiny app (in Windows)? This question provides code for alternating tabs with keyboard input, but I am interested in starting reactive flows. For example, a button is 'triggered' every time the user presses Q in the keyboard. NicE Here's an example based on this answer : library(shiny) runApp(shinyApp( ui = fluidPage( tags$script(HTML("$(function(){ $(document).keyup(function(e) { if (e.which == 81) { $('#button').click() } }); })")), actionButton("button", "An action button"), textOutput("text")), server=function(input, output,

R Shiny Input Reactivity Error on Drag-and-Drop

一个人想着一个人 提交于 2019-12-04 18:46:47
Im currently creating a R Shiny app with some custom js to provide drag and drop functionality. While the drag and drop works perfectly for a single file, when I reset it using shinyJS, uploading the same file again does not work properly. I understand that this is because the onchange function is not being triggerred with the file with the same name being re-inputted (regardless of if the file contents have been modified) JS: var datasets = {}; var dragOver = function(e) { e.preventDefault(); }; var dropData = function(e) { e.preventDefault(); handleDrop(e.dataTransfer.files); }; var

Reactive Framework / DoubleClick

核能气质少年 提交于 2019-12-04 16:48:29
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.... The TimeInterval method will give you the time between values. public static IObservable<Unit> DoubleClicks<TSource>( this

How to buffer stream using fromWebSocket Subject

こ雲淡風輕ζ 提交于 2019-12-04 16:42:34
This RxJava buffer example (with marble chart !) describes the desired result perfectly: collect items in buffers during the bursty periods and emit them at the end of each burst, by using the debounce operator to emit a buffer closing indicator to the buffer operator Edit: having reviewed How to create a RxJS buffer that groups elements in NodeJS but that does not rely on forever running interval? , my issue appears related to using a Subject as opposed to straight Observable . Using the socket stream to generate window close events (as follows) results in 2 sockets opened and no events

Unexplainable lack of performance improvement using RxJava Observables in Web Applications

与世无争的帅哥 提交于 2019-12-04 16:41:08
问题 I am performing some tests to evaluate if there is a real advantage in using reactive API's based on Observables, instead of the blocking traditional ones. The whole example is available on Githug Surprisingly the results show that the thoughput results are: The best : REST Services that return a Callable / DeferredResult that wraps the blocking operations. Not that bad : Blocking REST Services. The worst : REST Services that return a DeferredResult whose result is set by a RxJava Observable

reactive-banana: Firing event that contain the most up to date value of a Behavior

不羁的心 提交于 2019-12-04 16:18:57
问题 Suppose I have an event trigger which I want to do two things when fired. First, I want it to update the value of some behavior . Second, if other conditions are met, I want it to fire another event send_off with the updated value of the behavior. Expressed in code form, suppose I have trigger :: Event b trigger = ... updateFromTrigger :: b -> (a -> a) updateFromTrigger = ... conditionFromTrigger :: b -> Bool conditionFromTrigger = ... behavior :: Behavior a behavior = accumB initial_value