Skip to content

Commit 0ef57b8

Browse files
committed
Add invoke operator function to RootCallable for enhanced execution syntax
1 parent 8f652d9 commit 0ef57b8

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

thread/src/main/java/dev/mmrlx/thread/ktx/RootCallable.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.mmrlx.thread.ktx
22

3+
import dev.mmrlx.thread.RootArgs
34
import dev.mmrlx.thread.RootCallable
45
import kotlinx.coroutines.flow.Flow
56

@@ -21,4 +22,18 @@ fun <T> RootCallable<T>.asFlow(): Flow<T> = rootFlow(this)
2122
*
2223
* @return The result of the [RootCallable] execution.
2324
*/
24-
suspend fun <T> RootCallable<T>.asThread(): T = rootThread(this)
25+
suspend fun <T> RootCallable<T>.asThread(): T = rootThread(this)
26+
27+
/**
28+
* Invokes the [RootCallable] instance as a function.
29+
*
30+
* This operator function allows for a concise syntax to execute the callable
31+
* logic, delegating the execution to the underlying thread mechanism.
32+
*
33+
* @return The result produced by the [RootCallable].
34+
*/
35+
suspend operator fun <T> RootCallable<T>.invoke(args: Map<String, Any>? = null): T {
36+
if (args == null) return rootThread(this)
37+
val mArgs = RootArgs.of(args)
38+
return rootThread(mArgs, this)
39+
}

0 commit comments

Comments
 (0)