Skip to content

Commit

Permalink
feat: Adds current state name and data getters to FSM StateManager (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrosPapapa authored Sep 9, 2024
1 parent 0b85262 commit 81c19d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/scala/com/suprnation/actor/fsm/FSM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ case class FSMBuilder[F[+_]: Parallel: Async: Temporal, S, D, Request, Response]
override def minimalContext: MinimalActorContext[F, Request, Response] =
context.asInstanceOf[MinimalActorContext[F, Request, Response]]

override def stateName: F[S] = currentStateRef.get.map(_.stateName)

override def stateData: F[D] = currentStateRef.get.map(_.stateData)

override def goto(nextStateName: S): F[State[S, D, Request, Response]] =
currentStateRef.get.map(currentState =>
State(nextStateName, currentState.stateData)
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/com/suprnation/actor/fsm/StateManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ trait StateManager[F[+_], S, D, Request, Response] {

def minimalContext: MinimalActorContext[F, Request, Response]

def stateName: F[S]

def stateData: F[D]

def forMax(timeoutData: Option[(FiniteDuration, Request)]): F[State[S, D, Request, Response]]

def goto(nextStateName: S): F[State[S, D, Request, Response]]
Expand Down

0 comments on commit 81c19d0

Please # to comment.