Reputation: 115
Is there a difference in calling one flow as subflow from another corda flow versus calling the same flow from a cordaservice class as serviceHub.startFlow?
In terms of thread utilization or suspending etc?
I encountered a scenario where calling a flow from CordaService function got me error like
java.lang.IllegalArgumentException: Transaction context is missing. This might happen if a suspendable method is not annotated with @Suspendable annotation.
whereas calling the same flows from another flow using subflows worked fine.
Upvotes: 0
Views: 97
Reputation: 583
One problem associated with using custom threadPool is that it is complex to get the results back from the subFlow within the service or the flow which initiates the service. If we were to use Future or CompletableFuture then it would defeat the purpose of running these subflows concurrently. We can use this approach more easily only when the subflow results are not needed for the initiator or the service.
Upvotes: 1
Reputation: 115
When we call a flow from service it good practice to call it from its own Thread to avoid Dead locks of transaction update.
Inside @CordaService class
private companion object {
val executor: Executor = Executors.newCachedThreadPool()
}
-------------------------------------------------------------------
executor.execute {
serviceHub.startFlow(RegisterCarFlow(update))
}
Upvotes: 1