mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-18 07:16:45 +00:00
Initial commit
This commit is contained in:
42
futur-reactor/.gitignore
vendored
Normal file
42
futur-reactor/.gitignore
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
24
futur-reactor/build.gradle.kts
Normal file
24
futur-reactor/build.gradle.kts
Normal file
@@ -0,0 +1,24 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
}
|
||||
|
||||
group = "dev.tommyjs"
|
||||
version = "1.0.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains:annotations:24.1.0")
|
||||
implementation(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()
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package dev.tommyjs.futur.reactor;
|
||||
|
||||
import dev.tommyjs.futur.promise.Promise;
|
||||
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) {
|
||||
Promise<T> promise = new Promise<>();
|
||||
mono.doOnSuccess(promise::complete).doOnError(promise::completeExceptionally).subscribe();
|
||||
return promise;
|
||||
}
|
||||
|
||||
public static <T> @NotNull Promise<@NotNull List<T>> wrapFlux(@NotNull Flux<T> flux) {
|
||||
Promise<List<T>> promise = new Promise<>();
|
||||
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();
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user