Skip to content

Instantly share code, notes, and snippets.

@msdx
Created October 26, 2017 12:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msdx/3a80a2a7fe3048d626a117918392c5fb to your computer and use it in GitHub Desktop.
Save msdx/3a80a2a7fe3048d626a117918392c5fb to your computer and use it in GitHub Desktop.
rxjava countdown
Subscription subscription = Observable.interval(0, 1, TimeUnit.SECONDS)
.take(seconds + 1)
.map(new Func1<Long, Long>() {
@Override
public Long call(Long past) {
return seconds - past - 1;
}
})
.filter(new Func1<Long, Boolean>() {
@Override
public Boolean call(Long aLong) {
return aLong >= 0;
}
})
.subscribe(new RxAction<Long>() {
@Override
public void onNext(Long time) {
Log.e("xxxxxx", "onNext" + time);
}
@Override
public void onStart() {
Log.e("xxxxxx", "onStart");
}
@Override
public void onCompleted() {
Log.e("xxxxxx", "onCompleted");
}
});
@msdx
Copy link
Author

msdx commented Oct 26, 2017

9.8.7.6.5.4.3.2.1.0.complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment