xxfast
09/06/2022, 10:50 PMkotlinx-serialization-json-okio
like this in commonMain
class ValueStore<T: Any>(
val path: Path,
val serializer: Json = Json,
..
) {
suspend inline fun <reified V: T> set(value: V?) = lock.withLock {
stateFlow.emit(value)
serializer.encodeToBufferedSink(value, FILE_SYSTEM.sink(path).buffer())
}
}
And have a commonTest
written up like
private val store: ValueStore<Pet> = ValueStore(path = "test.json".toPath())
@Test
fun testWriteValue() = runTest {
val mylo = Pet(name = "Mylo", age = 1, type = Cat)
store.set(mylo)
val actual: Pet? = store.get<Pet>()
val expect: Pet = mylo
assertSame(expect, actual)
}
This test is failing 🤔 Although, I can see the test.json
file being created, but it is empty. Am I using this correctly? Full source herejw
09/06/2022, 10:51 PMuse
the result of buffer()
jw
09/06/2022, 10:52 PMjw
09/06/2022, 10:52 PMuse
will close which will flush firstxxfast
09/06/2022, 10:55 PMxxfast
09/06/2022, 10:56 PMsuspend inline fun <reified V: T> set(value: V?) = lock.withLock {
stateFlow.emit(value)
FILE_SYSTEM.sink(path).buffer().use { sink: BufferedSink ->
serializer.encodeToBufferedSink(value, sink)
}
}
xxfast
09/06/2022, 11:01 PM