Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(question) how can I show the task progress with RxJava? #451

Closed
letroll opened this issue Oct 24, 2013 · 2 comments
Closed

(question) how can I show the task progress with RxJava? #451

letroll opened this issue Oct 24, 2013 · 2 comments

Comments

@letroll
Copy link

letroll commented Oct 24, 2013

No description provided.

@abersnaze
Copy link
Contributor

This is a snippet of groovy code that will probably do most of what you want.

input = from([1,2,3,4])

// we are going to be branching off of the input observable three times so cache it.
cached = input.cache()

// produce an observable that is the fraction completed. In this case 0.25, 0.5, 0.75, 1
fract = cached.reduce(0, {count,value -> count+1}).mapMany({size -> cached.mapWithIndex({value,index -> (index+1)/size})})

// zip the fraction observable with the values to sync the timing of the values coming out with the fraction of completion
output = Observable.zip(cached,fract, {value, fractionDone ->
    // side effect to update progress bar with fraction done.
    println "done $fractionDone"
    return value
})

// OR

// if updating the status of a progress bar produces an observable you'll have to use this for the last zip
output = Observable.merge(Observable.zip(cached,fract, {value, fractionDone ->
    // operation to update progress bar with fraction done results in an observable too
    update = just("done $fractionDone")

    return zip(just(value), update, {value2, updateStatus -> value2})
}))

@benjchristensen
Copy link
Member

Closing out ... further conversation can be taken up on https://groups.google.com/d/forum/rxjava

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants