mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-17 23:16:01 +00:00
add generator for futur-lazy
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
.gradle
|
.gradle
|
||||||
build/
|
build/
|
||||||
|
node_modules/
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
!**/src/main/**/build/
|
!**/src/main/**/build/
|
||||||
!**/src/test/**/build/
|
!**/src/test/**/build/
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ subprojects {
|
|||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'org.jetbrains:annotations:24.1.0'
|
compileOnly 'org.jetbrains:annotations:24.1.0'
|
||||||
implementation 'org.slf4j:slf4j-api:2.0.12'
|
implementation 'org.slf4j:slf4j-api:2.0.12'
|
||||||
2
|
|
||||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
testImplementation 'io.projectreactor:reactor-core:3.6.4'
|
testImplementation 'io.projectreactor:reactor-core:3.6.4'
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public abstract class PromiseJoiner<V, K, T, R> {
|
public abstract class PromiseJoiner<V, K, T, R> {
|
||||||
@@ -29,7 +28,6 @@ public abstract class PromiseJoiner<V, K, T, R> {
|
|||||||
protected abstract R getResult();
|
protected abstract R getResult();
|
||||||
|
|
||||||
protected void join(@NotNull Iterator<V> promises, boolean link) {
|
protected void join(@NotNull Iterator<V> promises, boolean link) {
|
||||||
AtomicBoolean waiting = new AtomicBoolean();
|
|
||||||
AtomicInteger count = new AtomicInteger();
|
AtomicInteger count = new AtomicInteger();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -50,19 +48,15 @@ public abstract class PromiseJoiner<V, K, T, R> {
|
|||||||
Throwable e = onChildComplete(index, key, res);
|
Throwable e = onChildComplete(index, key, res);
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
joined.completeExceptionally(e);
|
joined.completeExceptionally(e);
|
||||||
} else if (count.decrementAndGet() == 0 && waiting.get()) {
|
} else if (count.decrementAndGet() == -1) {
|
||||||
joined.complete(getResult());
|
joined.complete(getResult());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} while (promises.hasNext());
|
} while (promises.hasNext());
|
||||||
|
|
||||||
if (!joined.isCompleted()) {
|
if (count.decrementAndGet() == -1) {
|
||||||
count.updateAndGet(v -> {
|
joined.complete(getResult());
|
||||||
if (v == 0) joined.complete(getResult());
|
|
||||||
else waiting.set(true);
|
|
||||||
return v;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,8 +48,9 @@ public abstract class AbstractPromise<T, FS, FA> implements CompletablePromise<T
|
|||||||
@NotNull ExceptionalFunction<T, V> completer
|
@NotNull ExceptionalFunction<T, V> completer
|
||||||
) {
|
) {
|
||||||
return () -> {
|
return () -> {
|
||||||
if (promise.isCompleted()) return;
|
if (!promise.isCompleted()) {
|
||||||
runCompleter(promise, () -> promise.complete(completer.apply(result)));
|
runCompleter(promise, () -> promise.complete(completer.apply(result)));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,17 +480,17 @@ public abstract class AbstractPromise<T, FS, FA> implements CompletablePromise<T
|
|||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
PromiseListener<T> listener = iter.next();
|
PromiseListener<T> listener = iter.next();
|
||||||
|
|
||||||
|
try {
|
||||||
if (listener instanceof AsyncPromiseListener) {
|
if (listener instanceof AsyncPromiseListener) {
|
||||||
callListenerAsync(listener, ctx);
|
callListenerAsync(listener, ctx);
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
callListenerNow(listener, ctx);
|
callListenerNow(listener, ctx);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
iter.forEachRemaining(v -> callListenerAsyncLastResort(v, ctx));
|
iter.forEachRemaining(v -> callListenerAsyncLastResort(v, ctx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void callListenerAsyncLastResort(PromiseListener<T> listener, PromiseCompletion<T> ctx) {
|
private void callListenerAsyncLastResort(PromiseListener<T> listener, PromiseCompletion<T> ctx) {
|
||||||
try {
|
try {
|
||||||
@@ -531,16 +532,18 @@ public abstract class AbstractPromise<T, FS, FA> implements CompletablePromise<T
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull CompletableFuture<T> toFuture() {
|
public @NotNull CompletableFuture<T> toFuture() {
|
||||||
CompletableFuture<T> future = new CompletableFuture<>();
|
CompletableFuture<T> future = new CompletableFuture<>();
|
||||||
this.addDirectListener(future::complete, future::completeExceptionally);
|
addDirectListener(future::complete, future::completeExceptionally);
|
||||||
future.whenComplete((_, e) -> {
|
future.whenComplete((_, e) -> {
|
||||||
if (e instanceof CancellationException) {
|
if (e instanceof CancellationException) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DeferredExecutionException extends ExecutionException {
|
private static class DeferredExecutionException extends ExecutionException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ package dev.tommyjs.futur.promise;
|
|||||||
* executed asynchronously by the {@link PromiseFactory} that created the completed promise.
|
* executed asynchronously by the {@link PromiseFactory} that created the completed promise.
|
||||||
*/
|
*/
|
||||||
public interface AsyncPromiseListener<T> extends PromiseListener<T> {
|
public interface AsyncPromiseListener<T> extends PromiseListener<T> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
|
|
||||||
public class ConcurrentResultArray<T> {
|
public class ConcurrentResultArray<T> {
|
||||||
|
|
||||||
private static final float RESIZE_THRESHOLD = 0.75F;
|
|
||||||
private static final float RESIZE_FACTOR = 1.2F;
|
private static final float RESIZE_FACTOR = 1.2F;
|
||||||
|
|
||||||
private final AtomicReference<T[]> ref;
|
private final AtomicReference<T[]> ref;
|
||||||
@@ -20,7 +19,7 @@ public class ConcurrentResultArray<T> {
|
|||||||
|
|
||||||
public void set(int index, T element) {
|
public void set(int index, T element) {
|
||||||
ref.updateAndGet(array -> {
|
ref.updateAndGet(array -> {
|
||||||
if (array.length * RESIZE_THRESHOLD <= index) {
|
if (array.length <= index) {
|
||||||
array = Arrays.copyOf(array, (int) (array.length * RESIZE_FACTOR));
|
array = Arrays.copyOf(array, (int) (array.length * RESIZE_FACTOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
futur-lazy/generator/bun.lockb
Normal file
BIN
futur-lazy/generator/bun.lockb
Normal file
Binary file not shown.
33
futur-lazy/generator/index.ts
Normal file
33
futur-lazy/generator/index.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const PACKAGE = "src/main/java/dev/tommyjs/futur"
|
||||||
|
const SIGNAL = "// Generated delegates to static factory"
|
||||||
|
|
||||||
|
const regex = /( {4}\/\*\*.+?)?((?:\S| )+? )(\S+)(\(.*?\))(?: {.+?}|;)/gs
|
||||||
|
const content = await Bun.file(`../../futur-api/${PACKAGE}/promise/PromiseFactory.java`).text()
|
||||||
|
|
||||||
|
const methods = [""]
|
||||||
|
for (const match of content.matchAll(regex)) {
|
||||||
|
let [_, docs, head, name, params] = match
|
||||||
|
|
||||||
|
head = head.trimStart()
|
||||||
|
if (head.startsWith("static")) continue
|
||||||
|
if (head.startsWith("default")) head = head.slice(8);
|
||||||
|
|
||||||
|
const args = Array.from(params.matchAll(/ ([a-zA-Z1-9]+)[,)]/gs))
|
||||||
|
.map(v => v[1]).join(", ")
|
||||||
|
|
||||||
|
methods.push(
|
||||||
|
[
|
||||||
|
`${docs} public static ${head}${name}${params} {`,
|
||||||
|
` return factory.${name}(${args});`,
|
||||||
|
" }"
|
||||||
|
].join("\n")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = Bun.file(`../${PACKAGE}/lazy/Promises.java`)
|
||||||
|
|
||||||
|
const existing = await output.text()
|
||||||
|
const cutIndex = existing.indexOf(SIGNAL) + SIGNAL.length;
|
||||||
|
const newContent = existing.slice(0, cutIndex) + methods.join("\n\n") + "\n\n}"
|
||||||
|
|
||||||
|
await Bun.write(output, newContent)
|
||||||
11
futur-lazy/generator/package.json
Normal file
11
futur-lazy/generator/package.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "generate-promises",
|
||||||
|
"module": "index.ts",
|
||||||
|
"type": "module",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/bun": "latest"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"typescript": "latest"
|
||||||
|
}
|
||||||
|
}
|
||||||
27
futur-lazy/generator/tsconfig.json
Normal file
27
futur-lazy/generator/tsconfig.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
// Enable latest features
|
||||||
|
"lib": ["ESNext", "DOM"],
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"allowJs": true,
|
||||||
|
|
||||||
|
// Bundler mode
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"noEmit": true,
|
||||||
|
|
||||||
|
// Best practices
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
|
||||||
|
// Some stricter flags (disabled by default)
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"noUnusedParameters": false,
|
||||||
|
"noPropertyAccessFromIndexSignature": false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,182 +27,520 @@ public final class Promises {
|
|||||||
Promises.factory = factory;
|
Promises.factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generated delegates to static factory
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new uncompleted promise.
|
||||||
|
*
|
||||||
|
* @return the new promise
|
||||||
|
*/
|
||||||
public static <T> @NotNull CompletablePromise<T> unresolved() {
|
public static <T> @NotNull CompletablePromise<T> unresolved() {
|
||||||
return factory.unresolved();
|
return factory.unresolved();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <K, V> @NotNull Promise<Map.Entry<K, V>> combine(@NotNull Promise<K> p1, @NotNull Promise<V> p2, boolean cancelOnError) {
|
/**
|
||||||
return factory.combine(p1, p2, cancelOnError);
|
* Creates a new promise, completed with the given value.
|
||||||
}
|
*
|
||||||
|
* @param value the value to complete the promise with
|
||||||
public static <K, V> @NotNull Promise<Map.Entry<K, V>> combine(@NotNull Promise<K> p1, @NotNull Promise<V> p2) {
|
* @return the new promise
|
||||||
return factory.combine(p1, p2);
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(
|
|
||||||
@NotNull Map<K, Promise<V>> promises,
|
|
||||||
@Nullable BiConsumer<K, Throwable> exceptionHandler,
|
|
||||||
boolean propagateCancel
|
|
||||||
) {
|
|
||||||
return factory.combine(promises, exceptionHandler, propagateCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises, @NotNull BiConsumer<K, Throwable> exceptionHandler) {
|
|
||||||
return factory.combine(promises, exceptionHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises, boolean cancelOnError) {
|
|
||||||
return factory.combine(promises, cancelOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises) {
|
|
||||||
return factory.combine(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<List<V>> combine(
|
|
||||||
@NotNull Iterator<Promise<V>> promises, int expectedSize,
|
|
||||||
@Nullable BiConsumer<Integer, Throwable> exceptionHandler, boolean propagateCancel
|
|
||||||
) {
|
|
||||||
return factory.combine(promises, expectedSize, exceptionHandler, propagateCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<List<V>> combine(
|
|
||||||
@NotNull Collection<Promise<V>> promises,
|
|
||||||
@NotNull BiConsumer<Integer, Throwable> exceptionHandler,
|
|
||||||
boolean propagateCancel
|
|
||||||
) {
|
|
||||||
return factory.combine(promises, exceptionHandler, propagateCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<List<V>> combine(
|
|
||||||
@NotNull Collection<Promise<V>> promises,
|
|
||||||
@NotNull BiConsumer<Integer, Throwable> exceptionHandler
|
|
||||||
) {
|
|
||||||
return factory.combine(promises, exceptionHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<List<V>> combine(@NotNull Collection<Promise<V>> promises, boolean cancelOnError) {
|
|
||||||
return factory.combine(promises, cancelOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<List<V>> combine(@NotNull Collection<Promise<V>> promises) {
|
|
||||||
return factory.combine(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<List<V>> combine(
|
|
||||||
@NotNull Stream<Promise<V>> promises,
|
|
||||||
@NotNull BiConsumer<Integer, Throwable> exceptionHandler,
|
|
||||||
boolean propagateCancel
|
|
||||||
) {
|
|
||||||
return factory.combine(promises, exceptionHandler, propagateCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<List<V>> combine(
|
|
||||||
@NotNull Stream<Promise<V>> promises,
|
|
||||||
@NotNull BiConsumer<Integer, Throwable> exceptionHandler
|
|
||||||
) {
|
|
||||||
return factory.combine(promises, exceptionHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<List<V>> combine(@NotNull Stream<Promise<V>> promises, boolean cancelOnError) {
|
|
||||||
return factory.combine(promises, cancelOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<List<V>> combine(@NotNull Stream<Promise<V>> promises) {
|
|
||||||
return factory.combine(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(
|
|
||||||
@NotNull Iterator<Promise<?>> promises, int estimatedSize, boolean propagateCancel) {
|
|
||||||
return factory.allSettled(promises, estimatedSize, propagateCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Collection<Promise<?>> promises, boolean propagateCancel) {
|
|
||||||
return factory.allSettled(promises, propagateCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Collection<Promise<?>> promises) {
|
|
||||||
return factory.allSettled(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Stream<Promise<?>> promises, boolean propagateCancel) {
|
|
||||||
return factory.allSettled(promises, propagateCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Stream<Promise<?>> promises) {
|
|
||||||
return factory.allSettled(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(boolean propagateCancel, @NotNull Promise<?>... promises) {
|
|
||||||
return factory.allSettled(propagateCancel, promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Promise<?>... promises) {
|
|
||||||
return factory.allSettled(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<Void> all(@NotNull Iterator<Promise<?>> promises, boolean cancelAllOnError) {
|
|
||||||
return factory.all(promises, cancelAllOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<Void> all(@NotNull Iterable<Promise<?>> promises, boolean cancelAllOnError) {
|
|
||||||
return factory.all(promises, cancelAllOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<Void> all(@NotNull Iterable<Promise<?>> promises) {
|
|
||||||
return factory.all(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<Void> all(@NotNull Stream<Promise<?>> promises, boolean cancelAllOnError) {
|
|
||||||
return factory.all(promises, cancelAllOnError);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<Void> all(@NotNull Stream<Promise<?>> promises) {
|
|
||||||
return factory.all(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<Void> all(boolean cancelAllOnError, @NotNull Promise<?>... promises) {
|
|
||||||
return factory.all(cancelAllOnError, promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<Void> all(@NotNull Promise<?>... promises) {
|
|
||||||
return factory.all(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<V> race(@NotNull Iterator<Promise<V>> promises, boolean cancelLosers) {
|
|
||||||
return factory.race(promises, cancelLosers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<V> race(@NotNull Iterable<Promise<V>> promises, boolean cancelLosers) {
|
|
||||||
return factory.race(promises, cancelLosers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<V> race(@NotNull Iterable<Promise<V>> promises) {
|
|
||||||
return factory.race(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<V> race(@NotNull Stream<Promise<V>> promises, boolean cancelLosers) {
|
|
||||||
return factory.race(promises, cancelLosers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V> @NotNull Promise<V> race(@NotNull Stream<Promise<V>> promises) {
|
|
||||||
return factory.race(promises);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> @NotNull Promise<T> wrap(@NotNull CompletableFuture<T> future) {
|
|
||||||
return factory.wrap(future);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull Promise<Void> start() {
|
|
||||||
return factory.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> @NotNull Promise<T> resolve(T value) {
|
public static <T> @NotNull Promise<T> resolve(T value) {
|
||||||
return factory.resolve(value);
|
return factory.resolve(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new promise, completed with {@code null}.
|
||||||
|
*
|
||||||
|
* @return the new promise
|
||||||
|
* @apiNote This method is often useful for starting promise chains.
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<Void> start() {
|
||||||
|
return factory.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new promise, completed exceptionally with the given error.
|
||||||
|
*
|
||||||
|
* @param error the error to complete the promise with
|
||||||
|
* @return the new promise
|
||||||
|
*/
|
||||||
public static <T> @NotNull Promise<T> error(@NotNull Throwable error) {
|
public static <T> @NotNull Promise<T> error(@NotNull Throwable error) {
|
||||||
return factory.error(error);
|
return factory.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new promise backed by the given future. The promise will be completed upon completion
|
||||||
|
* of the future.
|
||||||
|
*
|
||||||
|
* @param future the future to wrap
|
||||||
|
* @return the new promise
|
||||||
|
*/
|
||||||
|
public static <T> @NotNull Promise<T> wrap(@NotNull CompletableFuture<T> future) {
|
||||||
|
return factory.wrap(future);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines two promises into a single promise that completes when both promises complete. If
|
||||||
|
* {@code link} is {@code true} and either input promise completes exceptionally (including
|
||||||
|
* cancellation), the other promise will be cancelled and the output promise will complete
|
||||||
|
* exceptionally.
|
||||||
|
*
|
||||||
|
* @param p1 the first promise
|
||||||
|
* @param p2 the second promise
|
||||||
|
* @param link whether to cancel the other promise on error
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <K, V> @NotNull Promise<Map.Entry<K, V>> combine(@NotNull Promise<K> p1, @NotNull Promise<V> p2,
|
||||||
|
boolean link) {
|
||||||
|
return factory.combine(p1, p2, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines two promises into a single promise that completes when both promises complete. If either
|
||||||
|
* input promise completes exceptionally, the other promise will be cancelled and the output promise
|
||||||
|
* will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param p1 the first promise
|
||||||
|
* @param p2 the second promise
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <K, V> @NotNull Promise<Map.Entry<K, V>> combine(@NotNull Promise<K> p1, @NotNull Promise<V> p2) {
|
||||||
|
return factory.combine(p1, p2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines key-value pairs of inputs to promises into a single promise that completes with key-value
|
||||||
|
* pairs of inputs to outputs when all promises complete. If {@code link} is {@code true}
|
||||||
|
* and any promise completes exceptionally, the other promises will be cancelled and the output
|
||||||
|
* promise will complete exceptionally. If an exception handler is present, promises that fail
|
||||||
|
* will not cause this behaviour, and instead the exception handler will be called with the key
|
||||||
|
* that failed and the exception.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param exceptionHandler the exception handler
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises,
|
||||||
|
@Nullable BiConsumer<K, Throwable> exceptionHandler,
|
||||||
|
boolean link) {
|
||||||
|
return factory.combine(promises, exceptionHandler, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines key-value pairs of inputs to promises into a single promise that completes with key-value
|
||||||
|
* pairs of inputs to outputs when all promises complete. If any promise completes exceptionally,
|
||||||
|
* the exception handler will be called with the key that failed and the exception. The output promise
|
||||||
|
* will always complete successfully regardless of whether input promises fail.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param exceptionHandler the exception handler
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises,
|
||||||
|
@NotNull BiConsumer<K, Throwable> exceptionHandler) {
|
||||||
|
return factory.combine(promises, exceptionHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines key-value pairs of inputs to promises into a single promise that completes with key-value
|
||||||
|
* pairs of inputs to outputs when all promises complete. If {@code link} is {@code true}
|
||||||
|
* and any promise completes exceptionally, the other promises will be cancelled and the output
|
||||||
|
* promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises, boolean link) {
|
||||||
|
return factory.combine(promises, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines key-value pairs of inputs to promises into a single promise that completes with key-value
|
||||||
|
* pairs of inputs to outputs when all promises complete. If any promise completes exceptionally,
|
||||||
|
* the output promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises) {
|
||||||
|
return factory.combine(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an iterator of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If {@code link} is {@code true} and any promise completes exceptionally, all
|
||||||
|
* other promises will be cancelled and the output promise will complete exceptionally. If an exception
|
||||||
|
* handler is present, promises that fail will not cause this behaviour, and instead the exception
|
||||||
|
* handler will be called with the index that failed and the exception.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param exceptionHandler the exception handler
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<List<V>> combine(@NotNull Iterator<Promise<V>> promises, int expectedSize,
|
||||||
|
@Nullable BiConsumer<Integer, Throwable> exceptionHandler,
|
||||||
|
boolean link) {
|
||||||
|
return factory.combine(promises, expectedSize, exceptionHandler, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a collection of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If any promise completes exceptionally, the exception handler will be called with
|
||||||
|
* the index that failed and the exception. The output promise will always complete successfully regardless
|
||||||
|
* of whether input promises fail.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param exceptionHandler the exception handler
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<List<V>> combine(@NotNull Collection<Promise<V>> promises,
|
||||||
|
@NotNull BiConsumer<Integer, Throwable> exceptionHandler,
|
||||||
|
boolean link) {
|
||||||
|
return factory.combine(promises, exceptionHandler, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a collection of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If any promise completes exceptionally, the exception handler will be called with
|
||||||
|
* the index that failed and the exception. The output promise will always complete successfully regardless
|
||||||
|
* of whether input promises fail.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param exceptionHandler the exception handler
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<List<V>> combine(@NotNull Collection<Promise<V>> promises,
|
||||||
|
@NotNull BiConsumer<Integer, Throwable> exceptionHandler) {
|
||||||
|
return factory.combine(promises, exceptionHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a collection of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If {@code link} is {@code true} and any promise completes exceptionally, all
|
||||||
|
* other promises will be cancelled and the output promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<List<V>> combine(@NotNull Collection<Promise<V>> promises, boolean link) {
|
||||||
|
return factory.combine(promises, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a collection of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If any promise completes exceptionally, the output promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<List<V>> combine(@NotNull Collection<Promise<V>> promises) {
|
||||||
|
return factory.combine(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If {@code link} is {@code true} and any promise completes exceptionally, all
|
||||||
|
* other promises will be cancelled and the output promise will complete exceptionally. If an exception
|
||||||
|
* handler is present, promises that fail will not cause this behaviour, and instead the exception
|
||||||
|
* handler will be called with the index that failed and the exception.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param exceptionHandler the exception handler
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<List<V>> combine(@NotNull Stream<Promise<V>> promises,
|
||||||
|
@NotNull BiConsumer<Integer, Throwable> exceptionHandler,
|
||||||
|
boolean link) {
|
||||||
|
return factory.combine(promises, exceptionHandler, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If any promise completes exceptionally, the exception handler will be called with
|
||||||
|
* the index that failed and the exception. The output promise will always complete successfully regardless
|
||||||
|
* of whether input promises fail.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param exceptionHandler the exception handler
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<List<V>> combine(@NotNull Stream<Promise<V>> promises,
|
||||||
|
@NotNull BiConsumer<Integer, Throwable> exceptionHandler) {
|
||||||
|
return factory.combine(promises, exceptionHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If {@code link} is {@code true} and any promise completes exceptionally, all
|
||||||
|
* other promises will be cancelled and the output promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<List<V>> combine(@NotNull Stream<Promise<V>> promises, boolean link) {
|
||||||
|
return factory.combine(promises, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If any promise completes exceptionally, the output promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<List<V>> combine(@NotNull Stream<Promise<V>> promises) {
|
||||||
|
return factory.combine(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an iterator of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If {@code link} is {@code true} and any promise completes exceptionally, all
|
||||||
|
* other promises will be cancelled. The output promise will always complete successfully regardless
|
||||||
|
* of whether input promises fail.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param expectedSize the expected size of the list (used for optimization)
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Iterator<Promise<?>> promises,
|
||||||
|
int expectedSize, boolean link) {
|
||||||
|
return factory.allSettled(promises, expectedSize, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a collection of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If {@code link} is {@code true} and any promise completes exceptionally, all
|
||||||
|
* other promises will be cancelled. The output promise will always complete successfully regardless
|
||||||
|
* of whether input promises fail.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Collection<Promise<?>> promises,
|
||||||
|
boolean link) {
|
||||||
|
return factory.allSettled(promises, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a collection of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If any promise completes exceptionally, all other promises will be cancelled.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Collection<Promise<?>> promises) {
|
||||||
|
return factory.allSettled(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If {@code link} is {@code true} and any promise completes exceptionally, all
|
||||||
|
* other promises will be cancelled. The output promise will always complete successfully regardless
|
||||||
|
* of whether input promises fail.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Stream<Promise<?>> promises,
|
||||||
|
boolean link) {
|
||||||
|
return factory.allSettled(promises, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If any promise completes exceptionally, all other promises will be cancelled.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Stream<Promise<?>> promises) {
|
||||||
|
return factory.allSettled(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an array of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If {@code link} is {@code true} and any promise completes exceptionally, all
|
||||||
|
* other promises will be cancelled. The output promise will always complete successfully regardless
|
||||||
|
* of whether input promises fail.
|
||||||
|
*
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(boolean link,
|
||||||
|
@NotNull Promise<?>... promises) {
|
||||||
|
return factory.allSettled(link, promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an array of promises into a single promise that completes with a list of results when all
|
||||||
|
* promises complete. If any promise completes exceptionally, all other promises will be cancelled.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<List<PromiseCompletion<?>>> allSettled(@NotNull Promise<?>... promises) {
|
||||||
|
return factory.allSettled(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an iterator of promises into a single promise that completes when all promises complete.
|
||||||
|
* If {@code link} is {@code true} and any promise completes exceptionally, all other promises will
|
||||||
|
* be cancelled and the output promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<Void> all(@NotNull Iterator<Promise<?>> promises, boolean link) {
|
||||||
|
return factory.all(promises, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an iterable of promises into a single promise that completes when all promises complete.
|
||||||
|
* If {@code link} is {@code true} and any promise completes exceptionally, all other promises will
|
||||||
|
* be cancelled and the output promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<Void> all(@NotNull Iterable<Promise<?>> promises, boolean link) {
|
||||||
|
return factory.all(promises, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an iterable of promises into a single promise that completes when all promises complete.
|
||||||
|
* If any promise completes exceptionally, all other promises will be cancelled and the output
|
||||||
|
* promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<Void> all(@NotNull Iterable<Promise<?>> promises) {
|
||||||
|
return factory.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes when all promises complete.
|
||||||
|
* If {@code link} is {@code true} and any promise completes exceptionally, all other promises will
|
||||||
|
* be cancelled and the output promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<Void> all(@NotNull Stream<Promise<?>> promises, boolean link) {
|
||||||
|
return factory.all(promises, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes when all promises complete.
|
||||||
|
* If any promise completes exceptionally, all other promises will be cancelled and the output
|
||||||
|
* promise willcomplete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<Void> all(@NotNull Stream<Promise<?>> promises) {
|
||||||
|
return factory.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an array of promises into a single promise that completes when all promises complete.
|
||||||
|
* If {@code link} is {@code true} and any promise completes exceptionally, all other promises will
|
||||||
|
* be cancelled
|
||||||
|
* and the output promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param link whether to cancel all promises on any exceptional completions
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<Void> all(boolean link, @NotNull Promise<?>... promises) {
|
||||||
|
return factory.all(link, promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an array of promises into a single promise that completes when all promises complete.
|
||||||
|
* If any promise completes exceptionally, all other promises will be cancelled and the output
|
||||||
|
* promise will complete exceptionally.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static @NotNull Promise<Void> all(@NotNull Promise<?>... promises) {
|
||||||
|
return factory.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an iterator of promises into a single promise that completes when the first promise
|
||||||
|
* completes (successfully or exceptionally). If {@code cancelLosers} is {@code true}, all other
|
||||||
|
* promises will be cancelled when the first promise
|
||||||
|
* completes.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param cancelLosers whether to cancel the other promises when the first completes
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<V> race(@NotNull Iterator<Promise<V>> promises, boolean cancelLosers) {
|
||||||
|
return factory.race(promises, cancelLosers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an iterable of promises into a single promise that completes when the first promise
|
||||||
|
* completes (successfully or exceptionally). All other promises will be cancelled when the first
|
||||||
|
* promise completes.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<V> race(@NotNull Iterable<Promise<V>> promises, boolean cancelLosers) {
|
||||||
|
return factory.race(promises, cancelLosers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines an iterable of promises into a single promise that completes when the first promise
|
||||||
|
* completes (successfully or exceptionally). All other promises will be cancelled when the first
|
||||||
|
* promise completes.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<V> race(@NotNull Iterable<Promise<V>> promises) {
|
||||||
|
return factory.race(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes when the first promise
|
||||||
|
* completes (successfully or exceptionally). If {@code cancelLosers} is {@code true}, all other
|
||||||
|
* promises will be cancelled when the first promise completes.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @param cancelLosers whether to cancel the other promises when the first completes
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<V> race(@NotNull Stream<Promise<V>> promises, boolean cancelLosers) {
|
||||||
|
return factory.race(promises, cancelLosers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines a stream of promises into a single promise that completes when the first promise
|
||||||
|
* completes (successfully or exceptionally). All other promises will be cancelled when the first
|
||||||
|
* promise completes.
|
||||||
|
*
|
||||||
|
* @param promises the input promises
|
||||||
|
* @return the combined promise
|
||||||
|
*/
|
||||||
|
public static <V> @NotNull Promise<V> race(@NotNull Stream<Promise<V>> promises) {
|
||||||
|
return factory.race(promises);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user