mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-18 07:16:45 +00:00
better Mono wrapper and get groovy with Gradle
This commit is contained in:
11
futur-reactor/build.gradle
Normal file
11
futur-reactor/build.gradle
Normal file
@@ -0,0 +1,11 @@
|
||||
dependencies {
|
||||
compileOnly(project(":futur-api"))
|
||||
implementation("org.jetbrains:annotations:24.1.0")
|
||||
implementation("io.projectreactor:reactor-core:3.6.4")
|
||||
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
testImplementation("org.slf4j:slf4j-api:2.0.12")
|
||||
testImplementation("ch.qos.logback:logback-classic:1.5.3")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
|
||||
testImplementation(project(":futur-api"))
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
}
|
||||
|
||||
group = "dev.tommyjs"
|
||||
version = "2.1.2"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains:annotations:24.1.0")
|
||||
compileOnly(project(mapOf("path" to ":futur-api")))
|
||||
implementation("io.projectreactor:reactor-core:3.6.0")
|
||||
implementation(project(mapOf("path" to ":futur-reactive-streams")))
|
||||
testImplementation(platform("org.junit:junit-bom:5.9.1"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -3,29 +3,13 @@ package dev.tommyjs.futur.reactor;
|
||||
import dev.tommyjs.futur.promise.Promise;
|
||||
import dev.tommyjs.futur.promise.PromiseFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class ReactorTransformer {
|
||||
|
||||
public static <T> @NotNull Promise<T> wrapMono(@NotNull Mono<T> mono, PromiseFactory factory) {
|
||||
Promise<T> promise = factory.unresolved();
|
||||
mono.doOnSuccess(promise::complete).doOnError(promise::completeExceptionally).subscribe();
|
||||
return promise;
|
||||
}
|
||||
|
||||
public static <T> @NotNull Promise<@NotNull List<T>> wrapFlux(@NotNull Flux<T> flux, PromiseFactory factory) {
|
||||
Promise<List<T>> promise = factory.unresolved();
|
||||
AtomicReference<List<T>> out = new AtomicReference<>(new ArrayList<>());
|
||||
|
||||
flux.doOnNext(out.get()::add).subscribe();
|
||||
flux.doOnComplete(() -> promise.complete(out.get())).subscribe();
|
||||
flux.doOnError(promise::completeExceptionally).subscribe();
|
||||
|
||||
mono.subscribe(promise::complete, promise::completeExceptionally);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.tommyjs.futur.reactor;
|
||||
|
||||
import dev.tommyjs.futur.executor.SinglePoolExecutor;
|
||||
import dev.tommyjs.futur.impl.SimplePromiseFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class ReactorTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
Logger logger = LoggerFactory.getLogger(ReactorTest.class);
|
||||
var pfac = new SimplePromiseFactory(SinglePoolExecutor.create(1), logger);
|
||||
|
||||
ReactorTransformer.wrapMono(Mono.error(new Exception("Test Error")), pfac)
|
||||
.logExceptions("test");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user