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

org.reactfx.RepeatOnStream Maven / Gradle / Ivy

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

import org.reactfx.util.Tuple2;
import org.reactfx.util.Tuple3;

class RepeatOnStream extends LazilyBoundStream {
    private final EventStream source;
    private final EventStream impulse;

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

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

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

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

        return s1.and(s2);
    }
}

class RepeatOnBiStream
extends RepeatOnStream>
implements PoorMansBiStream {

    public RepeatOnBiStream(
            EventStream> source,
            EventStream impulse) {
        super(source, impulse);
    }
}

class RepeatOnTriStream
extends RepeatOnStream>
implements PoorMansTriStream {

    public RepeatOnTriStream(
            EventStream> source,
            EventStream impulse) {
        super(source, impulse);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy