I am parsing SVG files in an Observable. Points are emitted as \"Path\" object as the XML is parsed. Parsing happens in a separate thread and I want to draw the SVG file poi
You need to use the .zip()
operator with a .timer()
. From original RxJava wiki:
zip():
combine Observables together via a specified function and emit items based on the results of this function
timer():
create an Observable that emits a single item after a given delay
So, if you use zip()
to combine your original Observer
with timer()
, you can delay the output of each Path
every 50 msecs:
private void drawPath(final String chars) {
Observable.zip(
Observable.create(new Observable.OnSubscribe<Path>() {
// all the drawing stuff here
...
}),
Observable.timer(0, 50, TimeUnit.MILLISECONDS),
new Func2<Path, Long, Path>() {
@Override
public Path call(Path path, Long aLong) {
return path;
}
}
)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
...
}