org.reactfx.ThreadBridge Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
FX-Text-Area for formatted text and other special effects.
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