Initial commit

This commit is contained in:
tommyskeff
2023-11-19 20:55:02 +00:00
commit 08e97d81a4
34 changed files with 1807 additions and 0 deletions

42
futur-reactor/.gitignore vendored Normal file
View 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

View 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()
}

View File

@@ -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;
}
}