Skip to content

Instantly share code, notes, and snippets.

View jeroenr's full-sized avatar

Jeroen Rosenberg jeroenr

View GitHub Profile
interface Service {
Flux<String> findAll();
Mono<String> lookup(String s);
}
class Foo {
private final Service service;
Stream<String> problem() {
return service.findAll().toStream();
}
interface Service {
Flux<String> findAll();
}
class Foo {
private final Service service;
Iterable<String> problem() {
return service.findAll().toIterable();
}
}
interface Service {
Flux<String> findAll();
Mono<Void> operation(String s);
}
class Foo {
private final Service service;
Flux<Void> problem() {
return service.findAll()
.concatMap(service::operation);
interface Service {
Flux<String> findAll();
Mono<Void> operation(String s);
}
class Foo {
private final Service service;
Flux<Void> problem() {
return service.findAll()
.flatMap(service::operation, 4); // parallelism=4
interface Service {
Flux<String> findAll();
Mono<Void> operation(String s);
}
class Foo {
private final Service service;
Flux<Void> problem() {
return service.findAll()
.flatMap(service::operation);
abstract class UploadService {
protected Mono<Void> doUpload(InputStream in);
Mono<Void> upload(InputStream in) {
doUpload(in).doFinally(x -> in.close());
}
}
class Foo {
private final UploadService service;
Mono<Void> problem(byte[] data) {
interface Service {
Flux<Integer> findAll();
}
class Foo {
private final Service service;
Flux<Integer> problem() {
AtomicInteger count = new AtomicInteger();
return service.findAll()
.doOnNext(count::addAndGet)
interface Service {
Mono<String> create(String s);
Mono<Void> update(String s);
}
class Foo {
private final Service service;
Mono<Integer> problem() {
return service.create("foo").flatMap(foo ->
service.update(foo).thenReturn(foo.length())
interface Service {
Mono<String> create(String s);
Mono<Void> update(String s);
}
class Foo {
private final Service service;
Mono<Integer> problem() {
return service.create("foo").map(foo -> {
service.update(foo).subscribe();
interface Service {
Mono<Void> update(String s);
}
class Foo {
private final Service service;
void problem() {
service.update("foo").onErrorResume(e -> {
e.printStackTrace();
return Mono.empty();