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.

50 lines
1.2 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
  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.implicits._
  9. import java.util.concurrent.TimeoutException
  10. import monix.bio.IO
  11. import wow.doge.mygame.AppError.TimeoutError
  12. object AkkaUtils {
  13. def spawnActorOldL[T](
  14. spawnProtocol: ActorRef[SpawnProtocol.Command],
  15. actorName: String,
  16. behavior: Behavior[T]
  17. )(implicit timeout: Timeout, scheduler: Scheduler) =
  18. spawnProtocol.askL[ActorRef[T]](
  19. SpawnProtocol.Spawn(
  20. behavior,
  21. actorName,
  22. Props.empty,
  23. _
  24. )
  25. )
  26. def spawnActorL[T](
  27. behavior: Behavior[T],
  28. actorName: String,
  29. props: Props = Props.empty
  30. )(implicit
  31. timeout: Timeout,
  32. scheduler: Scheduler,
  33. spawnProtocol: ActorRef[SpawnProtocol.Command]
  34. ) =
  35. spawnProtocol
  36. .askL[ActorRef[T]](
  37. SpawnProtocol.Spawn(
  38. behavior,
  39. actorName,
  40. props,
  41. _
  42. )
  43. )
  44. // .onErrorHandleWith {
  45. // case ex: TimeoutException => IO.raiseError(TimeoutError(ex.getMessage))
  46. // }
  47. }