more KMP targets
This commit is contained in:
1 parent
3c33eb3bd9
commit
e9082af4de
8 files changed
+221
-13
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package net.sergeych.bintools
|
||||
|
||||
/**
|
||||
* Create per-platform default named storage.
|
||||
*
|
||||
* - In the browser, it uses the `Window.localStorage` prefixing items
|
||||
* by a string containing the [name]
|
||||
*
|
||||
* - In the JVM environment it uses folder-based storage on the file system. The name
|
||||
* is considered to be a folder name (the whole path which will be automatically created)
|
||||
* using the following rules:
|
||||
* - when the name starts with slash (`/`) it is treated as an absolute path to a folder
|
||||
* - when the name contains slash, it is considered to be a relative folder to the
|
||||
* `User.home` directory, like "`~/`" on unix systems.
|
||||
* - otherwise, the folder will be created in "`~/.local_storage`" parent directory
|
||||
* (which also will be created if needed).
|
||||
*
|
||||
* - For the native platorms it is not yet implemented (but will be soon).
|
||||
*
|
||||
* See [DataKVStorage] and [DataProvider] to implement a KVStorage on filesystems and like,
|
||||
* and `FileDataProvider` class on JVM target.
|
||||
*/
|
||||
actual fun defaultNamedStorage(name: String): KVStorage {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.sergeych.synctools
|
||||
|
||||
import kotlinx.atomicfu.locks.ReentrantLock
|
||||
|
||||
/**
|
||||
* Native implementation uses `ReentrantLock`]
|
||||
*/
|
||||
actual fun ProtectedOp(): ProtectedOpImplementation = object : ProtectedOpImplementation {
|
||||
private val access = ReentrantLock()
|
||||
override fun lock() {
|
||||
access.lock()
|
||||
}
|
||||
|
||||
override fun unlock() {
|
||||
access.unlock()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.sergeych.synctools
|
||||
|
||||
import kotlinx.coroutines.TimeoutCancellationException
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withTimeout
|
||||
|
||||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||
actual class WaitHandle {
|
||||
private val channel = Channel<Unit>()
|
||||
actual fun await(milliseconds: Long): Boolean {
|
||||
return runBlocking {
|
||||
try {
|
||||
if( milliseconds > 0) {
|
||||
withTimeout(milliseconds) {
|
||||
channel.receive()
|
||||
true
|
||||
}
|
||||
}
|
||||
else {
|
||||
channel.receive()
|
||||
true
|
||||
}
|
||||
}
|
||||
catch(_: TimeoutCancellationException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
actual fun wakeUp() {
|
||||
runBlocking { channel.send(Unit) }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user