• Stars
    star
    599
  • Rank 74,745 (Top 2 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Kotlin Multiplatform State Library

Stately

Stately is a state utility library to facilitate state management in Kotlin Multiplatform. It was originally written to facilitate development with the strick Kotlin/Native memory model. As of Kotlin 1.7.20, the strict model is deprecated, and the releveant modules of Stately have also been deprecated but are still published and available.

Stately currently provides concurrencly primitives and concurrent collections.

stately-concurrency

stately-concurrency includes some concurrency support classes. These include a set of Atomicxxx classes, a Lock, a ThreadLocal container, a Synchronizable type, and a class ThreadRef that allows you to hold a thread id.

Much of the functionality of this module is similar to atomic-fu. They differ in some ways, so while they both cover much of the same ground, Stately's version still has some use.

ThreadRef is unique to Stately. It allows you to capture a reference to the id of the thread in which it was created, and ask if the current thread is the same. Just FYI, it does not keep a reference to the actual thread. Just an id. Usage looks like this:

fun useRef(){
  val threadRef = ThreadRef()
  threadRef.same() // <- true
  backgrundThread {
    threadRef.same() // <- false
  }
}

The Synchronizable type allows us to use the JVM's synchronized but in common, and with Kotlin/Native which doesn't natively support it.

class MyMutableData(private var count: Int = 0) : Synchronizable() {
    fun add() {
        synchronize { count++ }
    }

    val myCount: Int
        get() = synchronize { count }
}

Your type should extend Synchronizable, which on the JVM is typealiased to Any. Then you can use synchronize as in the example above.

Config

commonMain {
    dependencies {
        implementation("co.touchlab:stately-concurrency:2.0.0")
    }
}

stately-concurrent-collections

A set of relatively simple mutable collections that are thread safe.

val list = ConcurrentMutableList<Int>()
val list.add(42)

Config

commonMain {
    dependencies {
        implementation("co.touchlab:stately-concurrent-collections:2.0.0")
    }
}

Subscribe!

We build solutions that get teams started smoothly with Kotlin Multiplatform Mobile and ensure their success in production. Join our community to learn how your peers are adopting KMM. Sign up here!

Primary Maintainer

Kevin Galligan

Image of Kevin

Ping me on twitter @kpgalligan if you don't get a timely reply! -Kevin

License

Copyright 2022 Touchlab, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

KaMPKit

KaMP Kit by Touchlab. A collection of code & tools designed to get your mobile team started quickly w/Kotlin Multiplatform
Kotlin
2,186
star
2

xcode-kotlin

Kotlin Native Xcode Plugin
Python
1,168
star
3

DroidconKotlin

Kotlin Multiplatfom app for Droidcon Events
Kotlin
1,027
star
4

SKIE

SKIE - Swift Kotlin Interface Enhancer
Kotlin
735
star
5

Kermit

Kermit by Touchlab is a Kotlin Multiplatform centralized logging utility.
JavaScript
715
star
6

KMMBridge

KMMBridge is a tool that helps publish Kotlin Multiplatform (KMP) Xcode binaries for use from Swift Package Manager (SPM) and CocoaPods.
JavaScript
361
star
7

CrashKiOS

Crash reporting for Kotlin/Native iOS applications
JavaScript
277
star
8

SQLiter

Minimal multiplatform sqlite library
C
177
star
9

cklib

Kotlin
92
star
10

SwiftCoroutines

Swift
58
star
11

compose-animations

Group of libraries to help you build better animations with Compose Multiplatform
Kotlin
53
star
12

KMMBridgeKickStart

Kotlin
33
star
13

compose-swiftui-codelab

Kotlin
27
star
14

SKIEDemoSample

SKIE Demo Application
Swift
22
star
15

KMMBridgeSKIETemplate

This template is for an old KMMBridge version. See https://touchlab.co/kmmbridge/spmquickstart
Kotlin
17
star
16

Karmok

Kotlin
15
star
17

KMMBridgeSampleKotlin

Kotlin
14
star
18

TestHelp

Some Kotlin Multiplatform test utilites
Kotlin
12
star
19

KMMWorker

Basic background threading for Kotlin Mobile Multiplatform
Kotlin
8
star
20

BadSwiftSimulator

Kotlin
6
star
21

GitPortalCli

Objective-C
6
star
22

KMMBridgeGithubWorkflow

5
star
23

KMMBridgeKickStart-Android

Kotlin
4
star
24

GitPortalTemplateLibrary

Kotlin
2
star
25

KmmBridgeIntegrationTest

Swift
2
star
26

KMMBridgeKickStart-iOS

Swift
2
star
27

schrodinger

What's this? Stay tuned...
2
star
28

KMMBridgeSPMQuickStart

KMMBridge v1 SPM Template
Kotlin
2
star
29

fkaction-installation-info

TypeScript
1
star
30

autoversion-nextversion

Calculates a sequential semver version for builds from a version base and git tags
TypeScript
1
star
31

KMMBridgeSampleSpm

Swift
1
star
32

KMMBridgeGitHubReleaseVersionTest

Swift
1
star
33

fkaction-merge-branch

TypeScript
1
star
34

KMMBridgeSampleCocoaPods

Swift
1
star
35

homebrew-touchlab

Ruby
1
star