org.reactfx.HookStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reactfx Show documentation
Show all versions of reactfx Show documentation
Reactive event streams for JavaFX
The newest version!
package org.reactfx;
import java.util.function.Consumer;
class HookStream extends EventStreamBase {
private final EventStream source;
private final Consumer super T> sideEffect;
private boolean sideEffectInProgress = false;
public HookStream(EventStream source, Consumer super T> sideEffect) {
this.source = source;
this.sideEffect = sideEffect;
}
@Override
protected Subscription observeInputs() {
return source.subscribe(t -> {
if(sideEffectInProgress) {
throw new IllegalStateException("Side effect is not allowed to cause recursive event emission");
}
sideEffectInProgress = true;
try {
sideEffect.accept(t);
} finally {
sideEffectInProgress = false;
}
emit(t);
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy