All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reactfx.EmitOnStream Maven / Gradle / Ivy

There is a newer version: 1.11
Show newest version
package org.reactfx;

/**
 * @see org.reactfx.EventStream#emitOn(EventStream)
 */
class EmitOnStream extends EventStreamBase {
    private final EventStream source;
    private final EventStream impulse;

    private boolean hasValue = false;
    private T value = null;

    public EmitOnStream(EventStream source, EventStream impulse) {
        this.source = source;
        this.impulse = impulse;
    }

    @Override
    protected Subscription observeInputs() {
        Subscription s1 = source.subscribe(v -> {
            hasValue = true;
            value = v;
        });

        Subscription s2 = impulse.subscribe(i -> {
            if(hasValue) {
                T val = value;
                hasValue = false;
                value = null;
                emit(val);
            }
        });

        return s1.and(s2);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy