org.saynotobugs.confidence.rxjava3.function.At Maven / Gradle / Ivy
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 super RxSubjectAdapter> delegate)
{
this(instant.toEpochMilli(), delegate);
}
/**
* Schedules an event at the given timestamp.
*/
public At(long timestamp, Quality super RxSubjectAdapter> 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