@@ -6,14 +6,19 @@ import java.util.function.Function
66interface Invoker {
77
88 companion object {
9+ @JvmStatic
10+ val defaultInstance = BaseInvoker ()
11+
912 @JvmStatic
1013 fun newInstance (): Invoker {
1114 return BaseInvoker ()
1215 }
1316 }
1417
1518 /* *
16- * Runs the given callable with the given mode applied
19+ * Runs the given callable with the given mode applied.
20+ *
21+ * The supplied mode is used to decorate the task by wrapping the task in the mode's [ModeWrapper].
1722 *
1823 * @param mode the custom mode that defines the task execution
1924 * @param task the callable to run
@@ -23,12 +28,20 @@ interface Invoker {
2328 @Throws(Exception ::class )
2429 fun <T > invoke (mode : Mode , task : Callable <T >): T
2530
31+ fun <T > invoke (task : Callable <T >): T {
32+ return invoke(Mode .empty, task)
33+ }
34+
2635 /* *
2736 * Same as [Invoker.invoke] but accepts a Runnable and does not throw a checked exception as Runnables
2837 * cannot throw checked exceptions
2938 */
3039 fun invoke (mode : Mode , runnable : Runnable )
3140
41+ fun invoke (runnable : Runnable ) {
42+ invoke(Mode .empty, runnable)
43+ }
44+
3245 /* *
3346 * Runs the task with the given mode applied and handles checked exceptions by wrapping them into runtime exceptions
3447 * using the given function.
@@ -41,10 +54,31 @@ interface Invoker {
4154 exceptionMapper : Function <Exception , RuntimeException >
4255 ): T
4356
57+ fun <T > invoke (
58+ task : Callable <T >,
59+ exceptionMapper : Function <Exception , RuntimeException >
60+ ): T {
61+ return invoke(
62+ Mode .empty,
63+ task,
64+ exceptionMapper
65+ )
66+ }
67+
4468 /* *
4569 * Runs the task wrapping checked exceptions into [RuntimeException]. This is equivalent to calling
4670 * `invoke(mode, task, e -> new RuntimeException(e))`
4771 */
4872 fun <T > invokeChecked (mode : Mode , task : Callable <T >): T
4973
50- }
74+ fun <T > invokeChecked (task : Callable <T >): T {
75+ return invokeChecked(Mode .empty, task)
76+ }
77+
78+ /* *
79+ * Creates a [CombinedInvoker] that combines Invokers by calling the supplied Invoker within this Invoker. Modes are
80+ * passed to the innermost invoke call
81+ */
82+ fun combine (invoker : Invoker ): Invoker
83+
84+ }
0 commit comments