Giter Club home page Giter Club logo

Comments (10)

akarnokd avatar akarnokd commented on May 31, 2024

Why don't you use the available operators to switch between modes?

datasource
.to(ParallelFlowable::from)
.runOn(Schedulers.computation())
.doOnNext(v -> { })
.sequential()
.observeOn(Schedulers.single())
.buffer(1000)
.doOnNext(list -> { })
.subscribe();

from rxjavaextensions.

frhack avatar frhack commented on May 31, 2024

Wonderful !
Very impressive power !
I forgot to say that the first computation is IO intensive. It's better to use another type of scheduler ?

(I'm still studying rxjava.)

from rxjavaextensions.

akarnokd avatar akarnokd commented on May 31, 2024

As you wish, the parallelism level is determined by the from parameter and not the Scheduler:

.to(f -> ParallelFlowable.from(f, 3))
.runOn(Schedulers.io())

from rxjavaextensions.

frhack avatar frhack commented on May 31, 2024

... and in this way the first doOnNext lambda is not executed when the second one is ?

from rxjavaextensions.

akarnokd avatar akarnokd commented on May 31, 2024

Stages will run in parallel, why do you have that requirement? RxJava is about executing in a flow and not blocking out things; backpressure is there to limit memory usage if that's the problem.

from rxjavaextensions.

frhack avatar frhack commented on May 31, 2024

I need to alternate the two stages.
Stage one is read only
Stage two is when results are saved

I need to isolate them, the application is much more simple and robust this way.
What I need is something like a blocking-output-buffer for the doOnNext operator. When it's full it blocks the doOnNext until the buffer is consumed

from rxjavaextensions.

akarnokd avatar akarnokd commented on May 31, 2024

The individual items should be isolated from each other anyway.

What I need is something like a blocking-output-buffer for the doOnNext operator. When it's full it blocks the doOnNext until the buffer is consumed

This makes no sense in reactive.

Here is an alternative that works on a chunk of 1000 elements:

datasource
.window(1000)
.flatMap(w ->
    ParallelFlowable.from(w)
    .runOn(Schedulers.io())
    .doOnNext(item -> { })
    .sequential()
    .toList()
    .doOnNext(list -> { })
    , 1)
.subscribe();

Here processing the items parallel happens before collecting them into a list and once that happens, you can process the list and there won't be any parallel execution from the first doOnNext nor there won't be another window started before you have finished with the list.

from rxjavaextensions.

frhack avatar frhack commented on May 31, 2024

OK that is a solution.
So it's not possible without buffering at start.
What's wrong with an operator that in loop do the following ?
do something with item,
collect item
emit items when the buffer is full

from rxjavaextensions.

akarnokd avatar akarnokd commented on May 31, 2024

What's wrong with an operator that in loop do the following ?

That's the imperative thinking about processing data. In reactive, there is no explicit loop but flow of data, aggregation, element processing, etc.

from rxjavaextensions.

frhack avatar frhack commented on May 31, 2024

ok... I'm still thinking in imperative mode.

from rxjavaextensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.