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

org.reactfx.ThreadBridge Maven / Gradle / Ivy

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

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

class ThreadBridge extends EventStreamBase {
    private final EventStream input;
    private final Executor sourceThreadExecutor;
    private final Executor targetThreadExecutor;

    public ThreadBridge(
            EventStream input,
            Executor sourceThreadExecutor,
            Executor targetThreadExecutor) {
        this.input = input;
        this.sourceThreadExecutor = sourceThreadExecutor;
        this.targetThreadExecutor = targetThreadExecutor;
    }

    @Override
    protected Subscription observeInputs() {
        CompletableFuture subscription = new CompletableFuture<>();
        sourceThreadExecutor.execute(() -> {
            subscription.complete(
                    input.subscribe(e -> {
                        targetThreadExecutor.execute(() -> emit(e));
                    }));
        });
        return () -> {
            subscription.thenAcceptAsync(
                    Subscription::unsubscribe,
                    sourceThreadExecutor);
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy