We’ve added support for Actor scheduling in Mikka. This means you can now easily schedule a message to be sent to an Actor at a set time either once or continuously.
Imagine you want to print some status once every 1 minute. An acceptable way to to this would be using a Timer object or a Thread with sleep.
But since we’re working with Actors and Akka has a Scheduler actor designed for this type of problem we’d rather make use of it than roll our own solution.
To send a message after an initial delay of 2 seconds and then once every second you can now write code like
Mikka::Scheduling.schedule(receiver_actor, 'message', 2, 1, :seconds)
If you instead want to send an Actor a message only once after 5 minutes you can write
Mikka::Scheduling.schedule_once(receiver_actor, 'message', 1, :minute)
In the code I’m currently working on I’m using my time_helper gem (https://github.com/gaiottino/time_helper) and since Mikka::Scheduling defaults to seconds I can write code like
# Send the message first after 2 minutes and then once every 30 seconds Mikka::Scheduling.schedule(receiver_actor, 'message', 2.minutes, 30.seconds)
That makes for some really simple and readable code