I using an Java library that has static method with Callable argument. Like:
import java.util.concurrent.Callable;
public class TransactionManager {
public static <T> T callInTransaction(Callable<T> callable) throws Exception {
return callable.call();
}
}
And I want to create help method in my application to call suspend block as Callable from method of library.
suspend inline fun <T> runInTransaction(crossinline call: suspend () -> T): T =
withContext(Dispatchers.IO) {
TransactionManager.callInTransaction {
call()
}
}
For call() invocation I get an error: "Suspension functions can be called only within coroutine body".
Is it possible to call suspend function without creating new coroutine?