commonMain.raven.LocalOutbox.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of raven-outbox-local-jvm Show documentation
Show all versions of raven-outbox-local-jvm Show documentation
An abstraction form sending emails
package raven
import koncurrent.Later
import koncurrent.later.then
import koncurrent.toLater
class LocalOutbox(
private val capacity: Int = DEFAULT_CAPACITY,
private val isSent: P.(to: String) -> Boolean
) : Outbox
{
companion object {
val DEFAULT_CAPACITY = 10
}
private val messages = mutableListOf
()
override fun store(params: P): Later
{
if (messages.size > capacity) {
messages.removeFirst()
}
messages.add(params)
return params.toLater()
}
override fun sent(to: String) = messages.filter { it.isSent(to) }.toLater()
override fun delete(receiver: String) = sent(to = receiver).then {
messages -= it
it
}
override fun toString() = "LocalOutbox(capacity = $capacity)"
}