Hello to all! How can I define an interface for th...
# coroutines
a
Hello to all! How can I define an interface for this method
suspend fun CoroutineScope.removeDuplicateTerminal(objectId: MutableList<Int>, token: String) = async { }
a
Hello. I don’t think an extension function can be extracted in an interface
What is your use case?
a
I use it in spring and want to make an autowired implementation through the interface.
a
It seems that I’m wrong. This looks valid
interface YourInterface { suspend fun CoroutineScope.removeDuplicateTerminal(objectId: MutableList<Int>, token: String) } class YourClass: YourInterface { override suspend fun CoroutineScope.removeDuplicateTerminal(objectId: MutableList<Int>, token: String) { } }
a
Thank! I hurried with the question 🙂
suspend fun CoroutineScope.removeDuplicateTerminal(objectId: MutableList<Int>, token: String): Deferred<Unit>
👍 1
t
If your function starts a coroutine that doesn't need to return a result, you may consider returning a
Job
instead of
Deferred<Unit>
, replacing
async
with
launch
. You can then
job.join()
to wait for the coroutine to complete its work.
👍 1
a
Yes, you are right! Thank you