Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package wow.doge.mygame.utils
  2. import akka.actor.typed.ActorRef
  3. import akka.actor.typed.Behavior
  4. import akka.actor.typed.Props
  5. import akka.actor.typed.Scheduler
  6. import akka.actor.typed.SpawnProtocol
  7. import akka.util.Timeout
  8. import wow.doge.mygame.AppError.TimeoutError
  9. import wow.doge.mygame.implicits._
  10. object AkkaUtils {
  11. def spawnActorOldL[T](
  12. spawnProtocol: ActorRef[SpawnProtocol.Command],
  13. actorName: String,
  14. behavior: Behavior[T]
  15. )(implicit timeout: Timeout, scheduler: Scheduler) =
  16. spawnProtocol.askL[ActorRef[T]](
  17. SpawnProtocol.Spawn(
  18. behavior,
  19. actorName,
  20. Props.empty,
  21. _
  22. )
  23. )
  24. def spawnActorL[T](
  25. behavior: Behavior[T],
  26. actorName: String,
  27. props: Props = Props.empty
  28. )(implicit
  29. timeout: Timeout,
  30. scheduler: Scheduler,
  31. spawnProtocol: ActorRef[SpawnProtocol.Command]
  32. ) =
  33. spawnProtocol
  34. .askL[ActorRef[T]](
  35. SpawnProtocol.Spawn(
  36. behavior,
  37. actorName,
  38. props,
  39. _
  40. )
  41. )
  42. .onErrorHandleWith(TimeoutError.from)
  43. }