commonMain.com.apadmi.mockzilla.lib.internal.service.MockServerMonitor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockzilla-jvm Show documentation
Show all versions of mockzilla-jvm Show documentation
Solution for running and configuring a local HTTP server on mobile.
The newest version!
package com.apadmi.mockzilla.lib.internal.service
import com.apadmi.mockzilla.lib.internal.models.LogEvent
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
internal interface MockServerMonitor {
suspend fun log(event: LogEvent)
suspend fun consumeCurrentLogs(): List
}
internal class MockServerMonitorImpl : MockServerMonitor {
private val lockingMutex = Mutex()
private val events: MutableList = mutableListOf()
override suspend fun log(event: LogEvent) = lockingMutex.withLock {
events.add(event)
Unit
}
override suspend fun consumeCurrentLogs(): List = lockingMutex.withLock {
val copy = mutableListOf().apply { addAll(events) }
events.clear()
copy
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy