enragedginger / akka-quartz-scheduler

Quartz Extension and utilities for cron-style scheduling in Akka
Other
559 stars 115 forks source link

Akka Typed sample #92

Closed captainmannering closed 4 years ago

captainmannering commented 4 years ago

Could the documentation be updated to give a simple example of having an Akka Typed Actor directly be the recipient of the message rather than a classic Actor?

enragedginger commented 4 years ago

Hi @captainmannering Are you wondering how one can use an Akka Typed Actor with this project? If so can you post some more details about the issues you're facing?

Regarding documentation, I'll happily consider a PR.

captainmannering commented 4 years ago

Maybe I am just thinking about it the wrong way, but for this method signature in the documentation:

def schedule(name: String, receiver: ActorRef, msg: AnyRef, startDate: Option[Date])

What if I have a typed actor instead? Is there a way to call schedule with types like this?..

sealed trait MyMessages
case object Tick extends MyMessages

def schedule(name: String, receiver: ActorRef[MyMessages], msg: Tick, startDate: Option[Date])

?

enragedginger commented 4 years ago

If I'm not mistaken, you should still be able to call the first definition of schedule as you have it listed there. Can you try that? Do you get any kind of error?

an-tex commented 4 years ago

You can convert a typed ActorRef[T] to a classic (untyped) ActorRef like this:

// this pulls e.g. an implicit .toClassic into scope
import akka.actor.typed.scaladsl.adapter._

sealed trait MyMessages
case object Tick extends MyMessages

val ref : ActorRef[MyMessages] = ???

scheduler.schedule("daily", ref.toClassic, Tick)

More on that: https://doc.akka.io/docs/akka/current/typed/coexisting.html#typed-to-classic

enragedginger commented 4 years ago

@captainmannering Does that resolve your issue?

captainmannering commented 4 years ago

Yes! thanks!