@@ -6,14 +6,19 @@ import java.util.function.Function
6
6
interface Invoker {
7
7
8
8
companion object {
9
+ @JvmStatic
10
+ val defaultInstance = BaseInvoker ()
11
+
9
12
@JvmStatic
10
13
fun newInstance (): Invoker {
11
14
return BaseInvoker ()
12
15
}
13
16
}
14
17
15
18
/* *
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].
17
22
*
18
23
* @param mode the custom mode that defines the task execution
19
24
* @param task the callable to run
@@ -23,12 +28,20 @@ interface Invoker {
23
28
@Throws(Exception ::class )
24
29
fun <T > invoke (mode : Mode , task : Callable <T >): T
25
30
31
+ fun <T > invoke (task : Callable <T >): T {
32
+ return invoke(Mode .empty, task)
33
+ }
34
+
26
35
/* *
27
36
* Same as [Invoker.invoke] but accepts a Runnable and does not throw a checked exception as Runnables
28
37
* cannot throw checked exceptions
29
38
*/
30
39
fun invoke (mode : Mode , runnable : Runnable )
31
40
41
+ fun invoke (runnable : Runnable ) {
42
+ invoke(Mode .empty, runnable)
43
+ }
44
+
32
45
/* *
33
46
* Runs the task with the given mode applied and handles checked exceptions by wrapping them into runtime exceptions
34
47
* using the given function.
@@ -41,10 +54,31 @@ interface Invoker {
41
54
exceptionMapper : Function <Exception , RuntimeException >
42
55
): T
43
56
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
+
44
68
/* *
45
69
* Runs the task wrapping checked exceptions into [RuntimeException]. This is equivalent to calling
46
70
* `invoke(mode, task, e -> new RuntimeException(e))`
47
71
*/
48
72
fun <T > invokeChecked (mode : Mode , task : Callable <T >): T
49
73
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