add generator for futur-lazy

This commit is contained in:
WhatCats
2025-01-06 23:08:59 +01:00
parent 4236adbd9e
commit 6174193145
11 changed files with 595 additions and 188 deletions

Binary file not shown.

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

View File

@@ -0,0 +1,11 @@
{
"name": "generate-promises",
"module": "index.ts",
"type": "module",
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "latest"
}
}

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

View File

@@ -27,182 +27,520 @@ public final class Promises {
Promises.factory = factory;
}
// Generated delegates to static factory
/**
* Creates a new uncompleted promise.
*
* @return the new promise
*/
public static <T> @NotNull CompletablePromise<T> 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);
}
public static <K, V> @NotNull Promise<Map.Entry<K, V>> combine(@NotNull Promise<K> p1, @NotNull Promise<V> p2) {
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();
}
/**
* Creates a new promise, completed with the given value.
*
* @param value the value to complete the promise with
* @return the new promise
*/
public static <T> @NotNull Promise<T> resolve(T 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) {
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);
}
}