From f196a0b621a2afa45c577bd2641331152691b134 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 13 Oct 2019 18:14:21 +0800 Subject: Add a simple `StateMachineActor` class --- cask/util/src/cask/util/BatchActor.scala | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cask/util/src/cask/util/BatchActor.scala b/cask/util/src/cask/util/BatchActor.scala index 26f1c14..fd4861e 100644 --- a/cask/util/src/cask/util/BatchActor.scala +++ b/cask/util/src/cask/util/BatchActor.scala @@ -34,4 +34,13 @@ abstract class BatchActor[T]()(implicit ec: ExecutionContext, } } } -} \ No newline at end of file +} + +abstract class StateMachine[T]() + (implicit ec: ExecutionContext, + log: Logger) { + class State(val run: T => State) + protected[this] def initialState: State + protected[this] var state: State = initialState + def run(items: Seq[T]): Unit = items.foreach{i => state = state.run(i)} +} -- cgit v1.2.3