Oleg Shuliak
02/09/2024, 10:27 AMprivate suspend fun doWork(
templateId: FormTemplateId?,
form: Form?,
workflow: DraftWorkflow
): DraftWorkflow {
return Pair(templateId, form).fold(
{ formTemplateId, formUpdate ->
updateUseCase.update(
formTemplateId,
formUpdate
)
workflow.setUrl()
},
{ formTemplateId ->
runBlocking {
deleteUseCase.delete(formTemplateId)
}
workflow
},
{ formCreate ->
val newFormId = runBlocking {
createUseCase.create(
formCreate
)
}
workflow
.setId(newFormId)
},
{
workflow
}
)
}
as you can see doWork()
is suspend function, but in lambda this suspend doesn’t work properly anymore.
updateUseCase.update()
in this case is a suspend function as well, but compiler gives me an error: Suspension functions can be called only within coroutine body,
So I have to wrap all calls to runBlocking
again to get the expected result.
any idea how that can be done without runBlocking?
Thanks in advance 🙏gsala
02/09/2024, 10:33 AMfold
are not suspending.
You can probably remove the fold
function and write simple if/else statements instead, assuming that the behavior of fold
is easy to inline.Oleg Shuliak
02/09/2024, 10:55 AMfold
and make it work 🙂Dmitry Khalanskiy [JB]
02/09/2024, 10:56 AMfold
can be made an inline
function, this will also work.