File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
core/src/commonTest/kotlin/com/powersync/testutils Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -16,10 +16,12 @@ import io.ktor.http.HttpStatusCode
1616import io.ktor.http.headersOf
1717import io.ktor.util.date.GMTDate
1818import io.ktor.utils.io.InternalAPI
19+ import io.ktor.utils.io.awaitFreeSpace
1920import io.ktor.utils.io.writeStringUtf8
2021import io.ktor.utils.io.writer
2122import kotlinx.coroutines.CoroutineScope
2223import kotlinx.coroutines.channels.ReceiveChannel
24+ import kotlinx.coroutines.channels.consume
2325import kotlinx.coroutines.channels.consumeEach
2426import kotlinx.serialization.encodeToString
2527
@@ -49,10 +51,15 @@ internal class MockSyncService(
4951 return if (data.url.encodedPath == " /sync/stream" ) {
5052 val job =
5153 scope.writer {
52- lines.consumeEach {
53- val serializedLine = JsonUtil .json.encodeToString(it)
54- channel.writeStringUtf8(" $serializedLine \n " )
55- channel.flush()
54+ lines.consume {
55+ while (true ) {
56+ // Wait for a downstream listener being ready before requesting a sync line
57+ channel.awaitFreeSpace()
58+ val line = receive()
59+ val serializedLine = JsonUtil .json.encodeToString(line)
60+ channel.writeStringUtf8(" $serializedLine \n " )
61+ channel.flush()
62+ }
5663 }
5764 }
5865
You can’t perform that action at this time.
0 commit comments