aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/moe/yuuta/workmode/async/StoppableGroup.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/moe/yuuta/workmode/async/StoppableGroup.kt')
-rw-r--r--app/src/main/java/moe/yuuta/workmode/async/StoppableGroup.kt28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/src/main/java/moe/yuuta/workmode/async/StoppableGroup.kt b/app/src/main/java/moe/yuuta/workmode/async/StoppableGroup.kt
new file mode 100644
index 0000000..ef651fe
--- /dev/null
+++ b/app/src/main/java/moe/yuuta/workmode/async/StoppableGroup.kt
@@ -0,0 +1,28 @@
+package moe.yuuta.workmode.async
+
+class StoppableGroup : Stoppable {
+ private val innerList: MutableList<Stoppable> = mutableListOf()
+
+ fun add(stoppable: Stoppable): StoppableGroup {
+ innerList.add(stoppable)
+ return this
+ }
+
+ fun remove(stoppable: Stoppable): StoppableGroup {
+ innerList.remove(stoppable)
+ return this
+ }
+
+ override fun stop() {
+ innerList.stream().forEach {
+ it.stop()
+ }
+ }
+
+ override fun isStopped(): Boolean {
+ for (stoppable in innerList) {
+ if (!stoppable.isStopped()) return false
+ }
+ return true
+ }
+} \ No newline at end of file