KotlinState
Interface for accessing Virtual Object/Workflow state in the reflection-based API.
This interface provides suspend-friendly state operations that can be used from within Restate handlers using the free-floating state() function.
Example usage:
@VirtualObject
class Counter {
companion object {
private val COUNT = stateKey<Long>("count")
}
@Handler
suspend fun increment(): Long {
val current = state().get(COUNT) ?: 0L
val next = current + 1
state().set(COUNT, next)
return next
}
}Content copied to clipboard