Kotlin Multiplatform implementation of threads, timers, atomic references, string utilities and iso8601 dates.
AtomicReference implementation on all platform
val atom = AtomicReference("a")
atom.compareAndSet("a", "b")
atom.setOrThrow("c", "b") // Will throw
val list = AtomicListReference<String>()
list.add("a") // Thread safely adds "a"
list.remove("a") // Thread safely removes "a"
Single and repeatable multiplatform timer implementations
val doOnceTimer = TimerFactory.single(12.seconds) { doSomething() }
val repeatTimer = TimerFactory.repeatable(12.seconds) { doSomething() }
repeatTimer.cancel() // stop the timer
Multiplatform string extensions for formating, normalizing
val string = "Où sont les bûches de Noël durant l'été?".normalize()
string == "Ou sont les buches de Noel durant l'ete?" // true
Multiplatform iso date implementation
val now = Date.now() // GMT
val date = now + 5.seconds
val isoDate = date.toISO8601() // yyyy-MM-dd:mm:dd:ssZ
val otherDate = Date.fromISO8601(isoDate)
otherDate == date // true
Allow freezing in common code. Does nothing in js and JVM.
freeze(objectToFreeze)
In swift, use access freeze via MrFreezeKt class helper to freeze object.
MrFreezeKt.freeze(objectToFreeze: objectToFreeze)
While waiting for Sharing of coroutines across threads in Kotlin/Native to work correctly. Trikot.foundation provide a standard Thread model based on queues. When this issue will be resolved, DispatchQueues will be converted to Coroutines.
See: Dispatch Queues
build.gradle
dependencies {
maven { url("https://s3.amazonaws.com/mirego-maven/public") }
}
ios() {
binaries {
framework {
export "com.mirego.trikot:trikotFoundation:$trikot_version"
}
}
}
sourceSets {
commonMain {
dependencies {
implementation "com.mirego.trikot:trikotFoundation:$trikot_version"
}
}
}