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

Method create

future-java/src/main/java/io/trane/future/Promise.java:135–167  ·  view source on GitHub ↗

Creates a new promise using a handler builder that it's based on the promise under creation. This method allows the user to define handlers that use the it's own promise. @param handlerBuilder a builder that receives the new promise and returns the interrupt handler of the new pro

(final Function<Promise<T>, InterruptHandler> handlerBuilder)

Source from the content-addressed store, hash-verified

133 * @return the new promise.
134 */
135 public static final <T> Promise<T> create(final Function<Promise<T>, InterruptHandler> handlerBuilder) {
136 final Optional<?>[] savedContext = Local.save();
137 if (savedContext.length == 0)
138 return new Promise<T>() {
139
140 final InterruptHandler handler = handlerBuilder.apply(this);
141
142 @Override
143 protected final Optional<?>[] getSavedContext() {
144 return Local.EMPTY;
145 }
146
147 @Override
148 protected final InterruptHandler getInterruptHandler() {
149 return handler;
150 }
151 };
152 else
153 return new Promise<T>() {
154
155 final InterruptHandler handler = handlerBuilder.apply(this);
156
157 @Override
158 protected final Optional<?>[] getSavedContext() {
159 return savedContext;
160 }
161
162 @Override
163 protected final InterruptHandler getInterruptHandler() {
164 return handler;
165 }
166 };
167 }
168
169 protected static final <T> Promise<T> apply(final InterruptHandler h1, final InterruptHandler h2) {
170 final Optional<?>[] savedContext = Local.save();

Callers 3

createMethod · 0.95
interruptibleMethod · 0.95
vFunction · 0.45

Calls 2

saveMethod · 0.95
applyMethod · 0.65

Tested by 1

createMethod · 0.76