Skip to content

Commit

Permalink
solved stackoverflowerror by returning no empty flowable and using th…
Browse files Browse the repository at this point in the history
…e takeWhile operator
  • Loading branch information
aemaem committed Aug 20, 2020
1 parent a3a3751 commit c2391cc
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/main/java/SwitchIfEmptyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,14 @@ public Flowable<String> two(String input) {
}, BackpressureStrategy.ERROR)
.flatMap(inputFlowable -> {
return source.read()
.toList()
.toFlowable()
.flatMap(strings -> {
Flowable<String> flowable = Flowable.empty();
for (String s : strings) {
flowable = flowable.switchIfEmpty(third(s));
}
return flowable;
});
.flatMap(this::third)
.takeWhile(s -> s.equals("false"));
});
}

public Flowable<String> third(String input) {
//System.out.println("Value " + input);
return Flowable.empty();
return Flowable.just("false");
}
}

Expand All @@ -54,7 +47,7 @@ public Flowable<String> read() {
emitter.onNext("Some values " + i);
}
emitter.onComplete();
}, BackpressureStrategy.ERROR);
}, BackpressureStrategy.BUFFER);
}
}
}

0 comments on commit c2391cc

Please sign in to comment.