We may generalize code a bit, too many repetition I think:
```
private <T> Flowable<T> create(Supplier<T> supplier) {
Flowable<T> flowable = Flowable.create(new FlowableOnSubscribe<T>() {
@Override
public void subscribe(FlowableEmitter<T> emitter) throws Exception {
try {
T response = supplier.get();
if (!emitter.isCancelled()) {
emitter.onNext(response);
}
if (!emitter.isCancelled()) {
emitter.onComplete();
}
} catch (Throwable e) {
if (!emitter.isCancelled()) {
emitter.onError(e);
}
}
}
}, BackpressureStrategy.DROP);
if (sc == null) {
return flowable;
}
return flowable.subscribeOn(sc).observeOn(sc);
}
```
Then the implementation is just needs a supplier:
```
@Override
public <T> Flowable<T> method(String name, Entity<?> entity, GenericType<T>
responseType) {
return create(() -> syncInvoker.method(name, entity, responseType));
}
@Override
public <T> Flowable<T> method(String name, Class<T> responseType) {
return create(() -> syncInvoker.method(name, responseType));
}
@Override
public <T> Flowable<T> method(String name, GenericType<T> responseType) {
return create(() -> syncInvoker.method(name, responseType));
}
```
What do you think?
[ Full content available at: https://github.com/apache/cxf/pull/451 ]
This message was relayed via gitbox.apache.org for [email protected]