| 450 | } |
| 451 | |
| 452 | public static void inMainThread(Runnable o) throws InterruptedException, ExecutionException { |
| 453 | if (!enabled || fiber.get() == null) |
| 454 | o.run(); |
| 455 | else { |
| 456 | CompletableFuture<Boolean> c = new CompletableFuture<>(); |
| 457 | RunLoop.main.once(() -> { |
| 458 | try { |
| 459 | o.run(); |
| 460 | c.complete(true); |
| 461 | } catch (Throwable t) { |
| 462 | t.printStackTrace(); |
| 463 | c.cancel(true); |
| 464 | } |
| 465 | }); |
| 466 | while (!c.isDone()) { |
| 467 | ThreadSync.yield(0); |
| 468 | } |
| 469 | if (c.isCompletedExceptionally()) { |
| 470 | c.get(); |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | public static class Stop extends RuntimeException { |
| 476 | |