Skip to content

Commit

Permalink
Fix laggy linkTableEntry (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawinganimal authored Feb 25, 2020
1 parent 0e782c3 commit 96610f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.sert2521.sertain.subsystems

import kotlinx.coroutines.Job

abstract class Subsystem(val name: String = "Anonymous Subsystem", val default: (suspend () -> Unit)? = null) {
abstract class Subsystem(val name: String = "Anonymous Subsystem", val default: (suspend () -> Any?)? = null) {
var isEnabled = true

internal var currentJob: Job? = null
Expand Down
13 changes: 5 additions & 8 deletions core/src/main/kotlin/org/sert2521/sertain/telemetry/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ package org.sert2521.sertain.telemetry

import kotlinx.coroutines.CoroutineScope
import org.sert2521.sertain.coroutines.watch
import org.sert2521.sertain.events.onTick

fun <T> CoroutineScope.linkTableEntry(name: String, parent: Table, get: () -> T) = run {
val entry = TableEntry(name, get(), parent)
get.watch {
onChange {
entry.value = value
}
onTick {
entry.value = get()
}
}

fun <T> CoroutineScope.linkTableEntry(name: String, vararg location: String, get: () -> T) = run {
val entry = TableEntry(name, get(), *location)
get.watch {
onChange {
entry.value = value
}
onTick {
entry.value = get()
}
}

Expand Down

0 comments on commit 96610f3

Please sign in to comment.