Skip to content

Commit

Permalink
Finish removing stately in favor of atomics
Browse files Browse the repository at this point in the history
  • Loading branch information
cedrickcooke committed Dec 8, 2020
1 parent 717d8aa commit 72534c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
5 changes: 0 additions & 5 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ object kotlinx {
version: String = "1.4.0"
) = "org.jetbrains.kotlinx:kotlinx-coroutines-$module:$version"
}

fun stately(
module: String,
version: String = "1.1.0-a1"
) = "co.touchlab:stately-$module:$version"
1 change: 0 additions & 1 deletion logging/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ kotlin {
implementation(project(":test"))
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation(stately("isolate"))
}
}

Expand Down
39 changes: 20 additions & 19 deletions logging/src/commonTest/kotlin/CallListLogger.kt
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
package com.juul.tuulbox.logging

import co.touchlab.stately.isolate.IsolateState
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.getAndUpdate

class CallListLogger : Logger {

private val mutableVerboseCalls = IsolateState { mutableListOf<Call>() }
val verboseCalls: List<Call> get() = mutableVerboseCalls.access { ArrayList(it) }
private val atomicVerboseCalls = atomic(emptyList<Call>())
val verboseCalls: List<Call> get() = atomicVerboseCalls.value

private val mutableDebugCalls = IsolateState { mutableListOf<Call>() }
val debugCalls: List<Call> get() = mutableDebugCalls.access { ArrayList(it) }
private val atomicDebugCalls = atomic(emptyList<Call>())
val debugCalls: List<Call> get() = atomicDebugCalls.value

private val mutableInfoCalls = IsolateState { mutableListOf<Call>() }
val infoCalls: List<Call> get() = mutableInfoCalls.access { ArrayList(it) }
private val atomicInfoCalls = atomic(emptyList<Call>())
val infoCalls: List<Call> get() = atomicInfoCalls.value

private val mutableWarnCalls = IsolateState { mutableListOf<Call>() }
val warnCalls: List<Call> get() = mutableWarnCalls.access { ArrayList(it) }
private val atomicWarnCalls = atomic(emptyList<Call>())
val warnCalls: List<Call> get() = atomicWarnCalls.value

private val mutableErrorCalls = IsolateState { mutableListOf<Call>() }
val errorCalls: List<Call> get() = mutableErrorCalls.access { ArrayList(it) }
private val atomicErrorCalls = atomic(emptyList<Call>())
val errorCalls: List<Call> get() = atomicErrorCalls.value

private val mutableAssertCalls = IsolateState { mutableListOf<Call>() }
val assertCalls: List<Call> get() = mutableAssertCalls.access { ArrayList(it) }
private val atomicAssertCalls = atomic(emptyList<Call>())
val assertCalls: List<Call> get() = atomicAssertCalls.value

override fun verbose(tag: String, message: String, throwable: Throwable?) {
mutableVerboseCalls.access { it += Call(tag = tag, message = message, throwable = throwable) }
atomicVerboseCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) }
}

override fun debug(tag: String, message: String, throwable: Throwable?) {
mutableDebugCalls.access { it += Call(tag = tag, message = message, throwable = throwable) }
atomicDebugCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) }
}

override fun info(tag: String, message: String, throwable: Throwable?) {
mutableInfoCalls.access { it += Call(tag = tag, message = message, throwable = throwable) }
atomicInfoCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) }
}

override fun warn(tag: String, message: String, throwable: Throwable?) {
mutableWarnCalls.access { it += Call(tag = tag, message = message, throwable = throwable) }
atomicWarnCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) }
}

override fun error(tag: String, message: String, throwable: Throwable?) {
mutableErrorCalls.access { it += Call(tag = tag, message = message, throwable = throwable) }
atomicErrorCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) }
}

override fun assert(tag: String, message: String, throwable: Throwable?) {
mutableAssertCalls.access { it += Call(tag = tag, message = message, throwable = throwable) }
atomicAssertCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) }
}
}

0 comments on commit 72534c6

Please sign in to comment.