MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / run

Method run

src/main/java/field/app/ThreadSync.java:222–289  ·  view source on GitHub ↗
(String tag, Supplier<K> in, Consumer<V> out, Callable<V> r, Consumer<Throwable> h)

Source from the content-addressed store, hash-verified

220
221
222 public <K, V> Fiber<K, V> run(String tag, Supplier<K> in, Consumer<V> out, Callable<V> r, Consumer<Throwable> h) throws InterruptedException {
223 Fiber<K, V> f = new Fiber<>();
224 live.add(f);
225 f.debugDescription = tag;
226 f.handler = h;
227 f.in = in;
228 f.input.put(in.get());
229 f.out = out;
230 threadingModel.set(this);
231 ClassLoader loader = Thread.currentThread()
232 .getContextClassLoader();
233
234 f.runner = executor.submit(() -> {
235
236 try {
237 Thread.currentThread()
238 .setName("" + f.debugDescription);
239 Thread.currentThread()
240 .setContextClassLoader(loader);
241
242 fiber.set(f);
243 f.input.take();
244
245 Object a = r.call();
246 if (a == null) f.output.put(NULL);
247 else f.output.put(a == null ? NULL : a);
248
249 return a;
250 } catch (Stop s) {
251 f.runner.cancel(true);
252 f.output.put(NULL);
253 return null;
254 } catch (Throwable t) {
255 f.exception = t;
256 f.runner.cancel(true);
257 System.err.println(" -- caught throwable ");
258 f.output.put(NULL);
259 t.printStackTrace();
260 System.err.println(" -- rethrowing <" + f.output.peek() + "> -> " + f.handler);
261 if (f.output.peek() == null) f.output.put(NULL);
262 throw t;
263 } finally {
264 // need to unwide sub fibers to allow recursion.
265 if (models.containsKey(Thread.currentThread())) {
266 ThreadSync m = ThreadSync.get();
267 m.shutdown();
268 }
269 fiber.set(null);
270 }
271 });
272 currentFiber = f;
273 try {
274
275 Object o = debugTake(f);
276 if (f.runner.isDone()) live.remove(this);
277 if (o == NULL) o = null;
278 out.accept((V) o);
279 f.lastReturn = o == NULL ? null : (V) o;

Callers 7

inMainThreadMethod · 0.45
callMethod · 0.45
launchMethod · 0.45
enterMainLoopMethod · 0.45
onceMethod · 0.45
performMethod · 0.45
exitMethod · 0.45

Calls 15

getMethod · 0.95
shutdownMethod · 0.95
debugTakeMethod · 0.95
NULLMethod · 0.95
discardMethod · 0.95
submitMethod · 0.80
setNameMethod · 0.80
takeMethod · 0.80
getMethod · 0.65
setMethod · 0.65
acceptMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected