Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Ignacio Baca Moreno-Torres
    @ibaca
    we have been using this to memoize a UI component, the component factory is exposed using a Single, so a Single<MyComponent> myComponent$ returns a new instance, if you want the instance to be cached forever you can do myComponent$.cache() but what we actually want is to cache the last component until it is hidden for more than X time, so this is our current code:
    static <T extends Component> Single<T> memoize(Single<T> src, int delay, TimeUnit unit) {
        BehaviorSubject<Single<T>> cache = BehaviorSubject.create();
        cache.onNext(memoize(src, delay, unit, cache));
        return cache.flatMapSingle(Rx.identity()).firstOrError();
    }
    
    static <T extends Component> Single<T> memoize(Single<T> src, int delay, TimeUnit unit, Observer<Single<T>> cache) {
        return src.doOnSuccess(c -> {
            // Instantiating component…
            var timeout = visible(c).switchMap(n -> n ? Observable.never() : timer(delay, unit)).firstOrError();
            //noinspection ResultOfMethodCallIgnored component should hide eventually, so this will get disposed
            timeout.subscribe(n -> {
                // Discarding component…
                cache.onNext(memoize(src, delay, unit, cache));
            });
        }).cache();
    }
    visibile(c) returns a Observable<Boolean>, it emmit the current state on subscription and changes when te component hides or reveal, the question or ask-for-suggestion is, how do you do this without a subject?
    (and removing this ugly subscribe :wink: )
    Ignacio Baca Moreno-Torres
    @ibaca
    no suggestion? :cry:
    uhm, anyway, if some one want to use RxJava in the browser remember that you can use rxjava-gwt (https://github.com/intendia-oss/rxjava-gwt), just released version 2.2.10-gwt1 :wink:
    Volkan Yazıcı
    @vy
    What is the preferred way of converting Reactor types to RxJava 1 types? I am hesitant to hack with Completable.fromFuture(mono.toFuture()) given blocking nature of Java Futures.
    David Stocking
    @dmstocking

    Dumb question. I can't find anything that does something like

    maybe.or { otherMaybe }

    I was kind of thinking maybe.concat { otherMaybe }.firstElement() but does that guarantee that otherMaybe will only be subscribed to if maybe is empty?

    Ignacio Baca Moreno-Torres
    @ibaca
    Maybe.empty().switchIfEmpty(Maybe.defer(() -> Maybe.just("lazyOther")))
    switchIfEmpty will only subscribe if maybeis empty
    David Stocking
    @dmstocking
    @ibaca That is it. I kept going over all the operators and I guess I just glossed over that one. Thanks for helping me find that.
    Ignacio Baca Moreno-Torres
    @ibaca
    :beers:
    Abhiroj
    @abhiroj
    Hi, how can a new open source contributor contribute? what are the labels that you use?
    Ewan Higgs
    @ehiggs
    Hi! Is there a way to see if a UnicastSubscriber has begun?
    Hongde Liu
    @enginespot
    Hi , I am studying the source code of rxjava , for the file EventLoopsScheduler.java there is a code like:@Override
    public void start() {
    FixedSchedulerPool update = new FixedSchedulerPool(threadFactory, MAX_THREADS);
    if (!pool.compareAndSet(NONE, update)) {
    update.shutdown();
    }
    }
    @Override
        public void start() {
            FixedSchedulerPool update = new FixedSchedulerPool(threadFactory, MAX_THREADS);
            if (!pool.compareAndSet(NONE, update)) {
                update.shutdown();
            }
        }
    sorry , I got it now:)
    skip my question here:)
    Davide Pugliese
    @Deviad
    Hello, can anyone help me to refactor this code:
     @Override
      public void onMessage(WebSocket webSocket, String text) {
        log.info(text);
    
        final ConnectableFlux<String> replay = inputBus.getEvents().replay(1);
    
        if (json == null && replay.autoConnect().hasElements().block()) {
          json = replay.autoConnect().next().block();
        }
        outputBus.setObject(text);
        webSocket.send(json);
      }
    ?
    I don’t wanna use block
    Pratap Koritala
    @pratap_koritala_twitter
    Hi, I am trying to use RxJava in a function called by the framework ( Map Reduce's map function). For this I can't use Reactive pull, so initialize PublishProcessor/PublishSubject and Flowable inside "setup ( called once) " function, and "onNext" inside "framework/MR map" function.
    But, It's not back pressured at map level with bounded size. I get an exception where the consumers are slow. Is there any workaround for this ? I can't use reactive pull, because I need to fit into the existing framework ( Map Reduce)
    Pratap Koritala
    @pratap_koritala_twitter
    Is this channel not active ?
    Ignacio Baca Moreno-Torres
    @ibaca
    :grin:
    Not sure what is your problem, maybe a bit of code will help, or create a stackoverflow question with more details
    David Karnok
    @akarnokd
    songjunyan
    @songjunyan
    native int hashCode()
    anyone know what in native hashCode()
    Who online
    Han van Venrooij
    @irundaia

    Hi everyone,

    I've got an Observable<T> and for each element in that observable, I want to perform some IO (which might potentially fail). Is there a way to use a forEach and combine it with a retry? Or is there some other pattern that I'm missing?

    Ignacio Baca Moreno-Torres
    @ibaca
    you can do many things… for example fileNames.flatMap(fn -> readFile(fn).retry(3)) or fileNames.flatMap(fn -> fn.readFile(fn)).toList().retry(3); but forEach is a terminal operator, do not even return an observable, so you should not use it if you want to apply retry the whole reading process
    Ólavur Debes Joensen
    @olavurdj

    Hi, I have an Observable<T> and want to use it to construct another Observable<T> that emits a value whenever the original observable emits one, and emits another (constant) value if the original observable doesn’t emit anything within a certain timeframe. For example, notifications are emitted, and I want to emit a ‘hide notification’ event if there are no other notifications are emitted before X seconds. I’ve tried switchMapping the original stream with just and delay observables (shown below), but it doesn’t seem that idiomatic, and I’m not sure if it will behave correctly. Is there an obvious solution to this that I’m missing? Using Kotlin and RxJava2.

    originalObs.switchMap { Observable.concat(Observable.just(it), Observable.just(FALLBACK_VALUE).delay(30, TimeUnit.SECONDS)) }

    Han van Venrooij
    @irundaia
    @ibaca thank you. I specifically do not want to retry the whole process, just the IO part. Basically I've got the following obsT.forEach(performIO). I'm guessing I could still just try to write a custom retry mechanism in the forEach itself.
    Ignacio Baca Moreno-Torres
    @ibaca
    @irundaia what are you doing in “performIO”?
    Ignacio Baca Moreno-Torres
    @ibaca
    @olavurdj this is an alternative, not sure if it is more ‘idomatic’
    events.publish(o -> o.mergeWith(o.debounce(30, TimeUnit.SECONDS).map(n -> FALLBACK)))
    Incubator
    @incube8r

    Hello, what is the proper way to merge Observable/Singles?

    public void testGetBlob() throws RequestException {
        TestData.getNewApplication().flatMap(testApplication -> {
            Client.initialize(testApplication.getAppId(), testApplication.getApiToken(), testApplication.getMasterKey());
            assertNotNull(testApplication.getApiToken());
            assertNotNull(testApplication.getAppId());
            assertNotNull(testApplication.getMasterKey());
            Entity entity = new Entity("Todo");
            return entity.create();
        }).flatMap(entity -> entity.setBlobProperty("text", "Hello world!".getBytes("UTF-8")))
                .flatMap(isSuccess -> {
                    if(isSuccess) {
                        // need to access `entity` at this point
                        return Single.just(isSuccess);
                    } else {
                        return Single.just(false);
                    }
                }).subscribe(success -> {
            Browser.getWindow().getConsole().log("Blob created");
            finishTest();
        }, error -> {
            Browser.getWindow().getConsole().error(error.getMessage());
            fail();
        });
        delayTestFinish(5000);
    }

    At the commented line, I need to be able to access the entity object, how can it be done?

    Ewan Higgs
    @ehiggs
    delayTestFinish(5000)? Is that like a sleep? I've been using .blockingGet(5, TimeUnit.SECONDS) or something like that.
    Ólavur Debes Joensen
    @olavurdj
    @ibaca I like your solution better, since I personally think debounce better reflects the intent of the action rather than my delay solution. Thank you!
    Sushant
    @sushantchoudhary
    Hello hivemind, I need some help with this Rxjava scenario :
    I have 2 observable sources where fetchProductList() returns Observable<Datasource> and other canInvite.execute() takes a value and returns a Single<Boolean>. I need to compose the stream to feed every emission from first source to the second in a way that I can return all the emission from fetchProductList() with the true value as a list. I tried to compose it this way but it looks a bit clunky, Any better/simpler ways to do it?
    fetchProductList()
                        .map { dataSource -> dataSource.data }
                        .flatMap{ data ->
                            Observable.from(data.roles.map { role ->
                                canInvite.execute(role.key).map { canInvite ->
                                    role to canInvite
                                }
                            })
                        }
    
                        .compose { it -> Single.merge(it) }
                        .filter { it -> it.second == true}
                        .map { it -> it.first }
                        .toList()
                        .subscribe {
    Ignacio Baca Moreno-Torres
    @ibaca
    fetchProductList()
            .flatMap { Observable.fromIterable(it.data.roles) }
            .flatMapMaybe { role -> canInvite(role).filter({it}).map({role}) }
            .distinct().toList()
    Sushant
    @sushantchoudhary
    Awesome, thanks a lot @ibaca

    From 3.x, the as() methods have been removed and the to() methods now each work with their respective XConverer interfaces:

    Flowable.to(Function<Flowable<T>, R>) is now Flowable.to(FlowableConverter<T, R>)
    Observable.to(Function<Observable<T>, R>) is now Observable.to(ObservableConverter<T, R>)
    Maybe.to(Function<Flowable<T>, R>) is now Maybe.to(MaybeConverter<T, R>)
    Single.to(Function<Flowable<T>, R>) is now Maybe.to(SingleConverter<T, R>)
    Completable.to(Function<Completable, R>) is now Completable.to(CompletableConverter<R>)
    ParallelFlowable.to(Function<ParallelFlowable<T>, R) is now ParallelFlowable.to(ParallelFlowableConverter<T, R>)

    Davide Pugliese
    @Deviad
    Hello
    Could anyone please tell me the right way to implement this:
      return command.kafkaMessageListener.bus.getEvents().serialize()
                       .flatMap(x-> {
                           if(x == null) {
                               return Flux.error(new NoMessageReceivedException());
                           }
                           return Flux.just(x);
                       }).doOnError(x-> Flux.just(new NoMessageReceivedException()))
                       .subscribeOn(Schedulers.single())
                       .retryBackoff(3, Duration.ofSeconds(1), Duration.ofSeconds(60))
                       .publishOn(Schedulers.single())
                       .collectList().block().get(0);
    ?
    I am trying to replace a countdown latch
    Grigore Cristian-Andrei
    @grrigore