Reputation: 842
I have house simulation where are various types of devices. These devices are generating events after some time period.
So I've decided to use new thread everytime when device (wash machine) is doing something (washing clothes) that is blocking for some time (eg. 2 minutes), so main thread is not blocked. This thread only sleeps for that period (2 minutes) and afterwards makes callback that washing is done.
Is it possible to use for this corountines in Kotlin? Would it be better?
Upvotes: 1
Views: 129
Reputation: 170899
If the rest of your application uses coroutines, it would make sense to do this with coroutines as well. If it doesn't, I don't see any benefit. However, you can use a ScheduledExecutorService
instead of doing it manually.
Upvotes: 2