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

org.saynotobugs.confidence.rxjava3.function.At Maven / Gradle / Ivy

There is a newer version: 0.58.0
Show newest version
package org.saynotobugs.confidence.rxjava3.function;

import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Scheduler;
import org.dmfs.jems2.bifunction.DelegatingBiFunction;
import org.dmfs.srcless.annotations.staticfactory.StaticFactories;
import org.saynotobugs.confidence.Quality;
import org.saynotobugs.confidence.rxjava3.RxSubjectAdapter;
import org.saynotobugs.confidence.rxjava3.adapters.EmitterAdapter;

import java.time.Instant;
import java.util.concurrent.TimeUnit;

@StaticFactories(value = "RxJava3", packageName = "org.saynotobugs.confidence.rxjava3")
public final class At extends DelegatingBiFunction, Flowable>
{

    /**
     * Schedules the given event at the given absolute time.
     */
    public At(Instant instant, Quality> delegate)
    {
        this(instant.toEpochMilli(), delegate);
    }


    /**
     * Schedules an event at the given timestamp.
     */
    public At(long timestamp, Quality> delegate)
    {
        super((scheduler, flowable) ->
            flowable.mergeWith(
                Completable.timer(timestamp - scheduler.now(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, scheduler)
                    .andThen(Flowable.create(emitter -> {
                            delegate.assessmentOf(new EmitterAdapter<>(emitter));
                            emitter.onComplete();
                        },
                        BackpressureStrategy.BUFFER))));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy