org.reactfx.EmitBothOnEachStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
FX-Text-Area for formatted text and other special effects.
package org.reactfx;
import static org.reactfx.util.Tuples.*;
import org.reactfx.util.Tuple2;
/**
* {@link EventStream#emitBothOnEach(EventStream)}
*/
class EmitBothOnEachStream extends EventStreamBase> {
private final EventStream source;
private final EventStream impulse;
private boolean hasValue = false;
private A a = null;
public EmitBothOnEachStream(EventStream source, EventStream impulse) {
this.source = source;
this.impulse = impulse;
}
@Override
protected Subscription observeInputs() {
Subscription s1 = source.subscribe(a -> {
hasValue = true;
this.a = a;
});
Subscription s2 = impulse.subscribe(i -> {
if(hasValue) {
emit(t(a, i));
}
});
return s1.and(s2);
}
}