Runtime is a runtime library for Ruby (oh, really?).
It runs in the background and waits for your created events to be ready to emit at the current time, thus making your multithreaded applications a tad easier to maintain.
How does it work
When you include the Runtime gem, it immediately creates an instance of Runtime::Manager which then spawns a thread that starts a loop. The loop then continues to check if one of your stored events are ready to pop.
You can force the Runtime library not to start by itself by setting
$NO_RUNTIME = true before including the gem.
If you want to enable Runtime at a later point, just call
How can I schedule my events
There's 2 methods that enables you to schedule your events to pop at a given time. They are called
in is a Ruby keyword, hence the _ prefix).
in method takes 1+ arguments.
The first one is 'when' you want it to pop (can be a
Time instance and a
Fixnum), and the other ones are if you want to pass them to your block when it's emitted.
at also takes 1+ arguments.
The first argument can be a String and a Time instance. A string example can be
"12:00 pm GMT+2" and it will pop at 12:00 pm according to the GMT+2 timezone.
Runtime provides 4 method extensions to the Fixnum class. Those are
Note: all methods also has a singularis alias which points to their respective pluralus method (
Raise an event that says "Hello world" in 5 minutes:
_in_ 10.minutes do puts "Hello world" end
Or raise an event that says "Hello world" in one day:
_in_ 1.day do puts "Hello world" end