MCPcopy Index your code
hub / github.com/ccxt/ccxt / race

Method race

java/lib/src/main/java/io/github/ccxt/ws/Future.java:70–85  ·  view source on GitHub ↗

Race multiple futures — returns a new Future that resolves/rejects when the first input future completes. Matches C# Future.race() and JS Promise.race().

(Future... futures)

Source from the content-addressed store, hash-verified

68 * Matches C# Future.race() and JS Promise.race().
69 */
70 public static Future race(Future... futures) {
71 Future result = new Future();
72 AtomicBoolean settled = new AtomicBoolean(false);
73 for (Future f : futures) {
74 f.completableFuture.whenComplete((val, ex) -> {
75 if (settled.compareAndSet(false, true)) {
76 if (ex != null) {
77 result.completableFuture.completeExceptionally(ex);
78 } else {
79 result.completableFuture.complete(val);
80 }
81 }
82 });
83 }
84 return result;
85 }
86}

Callers 3

testRaceMethod · 0.95
testRaceWithRejectMethod · 0.95
watchMultipleMethod · 0.45

Calls

no outgoing calls

Tested by 2

testRaceMethod · 0.76
testRaceWithRejectMethod · 0.76