From 7acd723c7085436c30947e65eae548a481893cc3 Mon Sep 17 00:00:00 2001 From: Aidan Heller Date: Fri, 26 Jun 2020 20:31:01 -0700 Subject: [PATCH] Improve subsystems (#79) * Add key/lock system * Make Key's constructor internal * Add invoke syntax --- core/src/main/kotlin/org/sert2521/sertain/subsystems/Tasks.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/kotlin/org/sert2521/sertain/subsystems/Tasks.kt b/core/src/main/kotlin/org/sert2521/sertain/subsystems/Tasks.kt index 3f80c6c..4d51aa7 100644 --- a/core/src/main/kotlin/org/sert2521/sertain/subsystems/Tasks.kt +++ b/core/src/main/kotlin/org/sert2521/sertain/subsystems/Tasks.kt @@ -45,6 +45,9 @@ suspend fun use(s1: S1, s2: S2, s3: S3, s4: S4, s5: S5, s6: S6, s7: S7, s8: S8, cancelConflicts: Boolean = true, name: String = "Unnamed Task", action: suspend CoroutineScope.(Key, Key, Key, Key, Key, Key, Key, Key) -> R) = reserve(s1, s2, s3, s4, s5, s6, s7, s8, cancelConflicts = cancelConflicts, name = name) { action(Key(), Key(), Key(), Key(), Key(), Key(), Key(), Key()) } +suspend operator fun S.invoke(cancelConflicts: Boolean = true, name: String = "Unnamed Task", action: suspend CoroutineScope.(Key) -> R) = + reserve(this, cancelConflicts = cancelConflicts, name = name) { action(Key()) } + suspend fun reserve( vararg subsystems: Subsystem, cancelConflicts: Boolean = true,