/** * Creates a new task that have a value of type {@code Void}. Because the * returned task returns no value, it is typically used to produce side effects. * It is not appropriate for long running or blocking actions. If action is * long running or blocking use {@link #blocking(String, Callable, Executor) blocking} method. * * <blockquote><pre> * // this task will print "Hello" on standard output * Task{@code <Void>} task = Task.action("greeting", () {@code ->} System.out.println("Hello")); * </pre></blockquote> * * Returned task will fail if {@code Action} passed in as a parameter throws * an exception. * <blockquote><pre> * // this task will fail with java.lang.ArithmeticException * Task{@code <Void>} task = Task.action("division", () {@code ->} System.out.println(2 / 0)); * </pre></blockquote> * <p> * @param desc a description the action, it will show up in a trace * @param action the action that will be executed when the task is run * @return the new task that will execute the action */ public static Task<Void> action(final String desc, final Action action) { ArgumentUtil.requireNotNull(action, "action"); return async(desc, () -> { action.run(); return Promises.VOID; }); }
/** * Creates a new task that have a value of type {@code Void}. Because the * returned task returns no value, it is typically used to produce side effects. * It is not appropriate for long running or blocking actions. If action is * long running or blocking use {@link #blocking(String, Callable, Executor) blocking} method. * * <blockquote><pre> * // this task will print "Hello" on standard output * Task{@code <Void>} task = Task.action("greeting", () {@code ->} System.out.println("Hello")); * </pre></blockquote> * * Returned task will fail if {@code Action} passed in as a parameter throws * an exception. * <blockquote><pre> * // this task will fail with java.lang.ArithmeticException * Task{@code <Void>} task = Task.action("division", () {@code ->} System.out.println(2 / 0)); * </pre></blockquote> * <p> * @param desc a description the action, it will show up in a trace * @param action the action that will be executed when the task is run * @return the new task that will execute the action */ public static Task<Void> action(final String desc, final Action action) { ArgumentUtil.requireNotNull(action, "action"); return async(desc, () -> { action.run(); return Promises.VOID; }); }