让 kotlin invoke() 函数 return a Deferred from Coroutine

Have the kotlin invoke() function return a Deferred from Coroutine

invoke 函数允许直接从 class.

中调用函数

我怎样才能让它与协程延迟结果一起工作?

我在下面尝试过,但我得到了 Type mismatch Required: Deferred<List<MyModel>> Found: MyUseCase

class MyUseCase(
    private val repository: MyRepository,
) {
    suspend operator fun invoke(id: String): Deferred<List<MyModel>> =
        CoroutineScope(IO).async {
            repository.fetchApi(id)
        }
    }
val deferredResult: Deferred<List<MyModel>> = viewModelUseCases.myUseCase

invoke 允许调用一个实例,就像它是一个函数一样,即带括号。您编写的 invoke 函数将被

调用
val deferredResult: Deferred<List<MyModel>> = viewModelUseCases.myUseCase()