Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Davide Pugliese
    @Deviad
    ?
    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
    Ota Mares
    @omares
    hey! would this be the right place to ask questions related to RxJava, Android & Databinding?
    Aditya Prerepa
    @adiprerepa
    Is rxjava good for server-side applications?
    David Karnok
    @akarnokd
    @omares Try StackOverflow with those tags.
    @adiprerepa It works but unless you are limited to Java 6, Project Reactor does support Java 8 natively.
    Patrick Lightbody
    @lightbody
    Hi there! I'm fairly new to RxJava, so apologies if this is too simple of a question... because the language is a bit different than I'm used to I'm finding my normal google-around-until-you-find-the-answer approach isn't working quite as well :) Anyway, on to the question: how might I design a flow such that a bit of code is executed only after a user's activity (as it comes through my API) has stopped for X seconds? My goal is to kick off a call to a downstream API, but only once the user has "chilled out" and stopped sending me data.
    My non-reactive brain is wanting to have a ConcurrentHashMap<UserId, Instant> that I update as user input comes in and then a thread that wakes up every 5s to check for values that are more than X seconds ago.
    slisaasquatch
    @slisaasquatch

    Hi, I have a question about the BackpressureStrategy I should use for Flowable.create when I'm only emitting 1 element.
    Right now I'm actually using Single.create like this:

      public static Flowable<Response> example1() {
        return Single.<Response>create(emitter -> {
          someAsyncMethod(new Callback() {
            @Override
            public void onFailure(Exception ex) {
              emitter.onError(ex);
            }
    
            @Override
            public void onSuccess(Response resp) {
              emitter.onSuccess(resp);
            }
          });
        }).toFlowable();
      }

    And I'm just wondering what BackpressureStrategy I should use if I do it like this:

      public static Flowable<Response> example2() {
        return Flowable.<Response>create(emitter -> {
          someAsyncMethod(new Callback() {
            @Override
            public void onFailure(Exception ex) {
              emitter.onError(ex);
            }
    
            @Override
            public void onSuccess(Response resp) {
              emitter.onNext(resp);
              emitter.onComplete();
            }
          });
        }, BackpressureStrategy.???);
      }

    Since I know there's only one element, I guess the BackpressureStrategy doesn't matter that much?

    Ignacio Baca Moreno-Torres
    @ibaca
    yep, the Single.create is the best solution :+1:, I will return the Single too instead of the Flowable
    slisaasquatch
    @slisaasquatch
    @ibaca The reason I'm returning the Flowable is that I need the return type to be a Publisher. I will probably keep using Single.create, but I'm still curious about what BackpressureStrategy would be the most appropriate if I were to use Flowable.create.
    Ignacio Baca Moreno-Torres
    @ibaca
    Buffer, but it is useless as the max required but size will be 1, just look at the source code of Single.toFlowable to find the best approach
    slisaasquatch
    @slisaasquatch
    So I did some more digging, and IMO BUFFER is not the right choice here, because FlowableCreate creates a buffer if you use BUFFER and it will never be used. Now I'm torn between ERROR and LATEST.
    slisaasquatch
    @slisaasquatch
    @lightbody The operator you'll probably want to look at is debounce.
    Here's a simple example:
      static final FlowableProcessor<Object> userActionProcessor =
          PublishProcessor.create().toSerialized();
    
      static void userAction() {
        // Some user action
        userActionProcessor.onNext(true); // Can be anything. Using true as a placeholder.
      }
    
      public static void main(String[] args) throws Throwable {
        userActionProcessor.onBackpressureDrop()
            .debounce(2500, TimeUnit.MILLISECONDS)
            .doOnNext(ignored -> {
              System.out.println("No user activity for 2.5 seconds!");
            })
            .subscribe();
    
        // Fake user actions
        Flowable.concat(Flowable.range(0, 5), Flowable.range(0, 2))
            .concatMap(i -> {
              return Flowable.timer(i, TimeUnit.SECONDS)
                  .doOnComplete(() -> {
                    System.out.printf("Calling userAction after a %d-second delay\n", i);
                    userAction();
                  });
            })
            .blockingSubscribe();
    
      }
    The output:
    Calling userAction after a 0-second delay
    Calling userAction after a 1-second delay
    Calling userAction after a 2-second delay
    No user activity for 2.5 seconds!
    Calling userAction after a 3-second delay
    No user activity for 2.5 seconds!
    Calling userAction after a 4-second delay
    Calling userAction after a 0-second delay
    Calling userAction after a 1-second delay
    xorander00
    @xorander00
    Hello :) Newbie question here, but...
    I'm currently using flatMap to chain a sequence of operations. All of them return Flowables which emit 1 or more values.
    At the end of the chain, .subscribe handles the emitted values. In the middle of the chain, the each flatMap call checks for a specific emission. If it matches, then it invokes another call and returns a Flowable. Anything that doesn't match, I just want to pass along the chain.
    I'm currently using Flowable.just(emission) to do that, but I'm not sure that it's correct (even though it seems to work).
    I feel like there's a better way to do this, but I'm currently stalled on my options due to my inexperience :)
    xorander00
    @xorander00
    I was, and still am, exploring the available operators. I looked at merge, zip, concat, etc. So far it looks like flatMap is what I want. Also, I wasn't sure how best to just pass along the emissions in a flatMap.
    Lazar Bulić
    @pendula95
    Can you share a code example so we can inspect? @xorander00