/** * Runs an action in a new fiber and awaits the fiber's termination. * Unlike {@link #runInFiber(SuspendableRunnable) runInFiber} this method does not throw {@link ExecutionException}, but wraps * any checked exception thrown by the operation in a {@link RuntimeException}, unless it is of the given {@code exception type}, in * which case the checked exception is thrown as-is. * * @param scheduler the {@link FiberScheduler} to use when scheduling the fiber. * @param target the operation * @param exceptionType a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is. * @throws InterruptedException */ public static <X extends Exception> void runInFiberChecked(FiberScheduler scheduler, SuspendableRunnable target, Class<X> exceptionType) throws X, InterruptedException { try { new Fiber<Void>(scheduler, target).start().join(); } catch (ExecutionException ex) { throw throwChecked(ex, exceptionType); } }
/** * Runs an action in a new fiber, awaits the fiber's termination, and returns its result. * Unlike {@link #runInFiber(FiberScheduler, SuspendableCallable) runInFiber} this method does not throw {@link ExecutionException}, but wraps * any checked exception thrown by the operation in a {@link RuntimeException}, unless it is of the given {@code exception type}, in * which case the checked exception is thrown as-is. * * @param <V> * @param scheduler the {@link FiberScheduler} to use when scheduling the fiber. * @param target the operation * @param exceptionType a checked exception type that will not be wrapped if thrown by the operation, but thrown as-is. * @return the operations return value * @throws InterruptedException */ public static <V, X extends Exception> V runInFiberChecked(FiberScheduler scheduler, SuspendableCallable<V> target, Class<X> exceptionType) throws X, InterruptedException { try { return new Fiber<V>(scheduler, target).start().get(); } catch (ExecutionException ex) { throw throwChecked(ex, exceptionType); } }