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

org.reactfx.EmitAllOnEachStream Maven / Gradle / Ivy

There is a newer version: 2.0-M5
Show newest version
package org.reactfx;


class EmitBothOnEachStream extends LazilyBoundBiStream {
    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 subscribeToInputs() {
        Subscription s1 = source.subscribe(a -> {
            hasValue = true;
            this.a = a;
        });

        Subscription s2 = impulse.subscribe(i -> {
            if(hasValue) {
                emit(a, i);
            }
        });

        return s1.and(s2);
    }
}

class EmitAll3OnEachStream extends LazilyBoundTriStream {
    private final BiEventStream source;
    private final EventStream impulse;

    private boolean hasValue = false;
    private A a = null;
    private B b = null;

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

    @Override
    protected Subscription subscribeToInputs() {
        Subscription s1 = source.subscribe((a, b) -> {
            hasValue = true;
            this.a = a;
            this.b = b;
        });

        Subscription s2 = impulse.subscribe(i -> {
            if(hasValue) {
                emit(a, b, i);
            }
        });

        return s1.and(s2);
    }
}