简体   繁体   中英

Usage of Kotlin Coroutines

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM