MCPcopy Create free account
hub / github.com/traneio/future / trySetState

Method trySetState

future-java/src/main/java/io/trane/future/Promise.java:237–265  ·  view source on GitHub ↗
(final Future<T> result)

Source from the content-addressed store, hash-verified

235 }
236
237 @SuppressWarnings("unchecked")
238 public final boolean trySetState(final Future<T> result) {
239 try {
240 while (true) {
241 final Object curr = state;
242 if (curr instanceof SatisfiedFuture)
243 return false;
244 else if (curr instanceof Promise && !(curr instanceof Continuation))
245 return ((Promise<T>) curr).becomeIfEmpty(result);
246 else if (curr instanceof LinkedContinuation)
247 return ((LinkedContinuation<?, T>) curr).becomeIfEmpty(result);
248 else if (result instanceof Promise) {
249 ((Promise<T>) result).compress().link(this);
250 return true;
251 } else if (cas(curr, result)) {
252 if (curr != null)
253 ((WaitQueue<T>) curr).flush(result);
254 return true;
255 }
256 }
257 } catch (final StackOverflowError ex) {
258 if (!(this instanceof Continuation))
259 LOGGER.log(Level.SEVERE,
260 "FATAL: Stack overflow when satisfying promise, the promise and its continuations won't be satisfied. "
261 + "Use `Future.tailrec` or increase the stack size (-Xss) if the future isn't recursive.",
262 ex);
263 throw ex;
264 }
265 }
266
267 @SuppressWarnings("unchecked")
268 protected final WaitQueue<T> safeFlush(final Future<T> result) {

Callers 1

becomeIfEmptyMethod · 0.95

Calls 5

casMethod · 0.95
linkMethod · 0.80
compressMethod · 0.80
flushMethod · 0.65
becomeIfEmptyMethod · 0.45

Tested by

no test coverage detected