Module: Ztimer
- Defined in:
- lib/ztimer.rb,
lib/ztimer/slot.rb,
lib/ztimer/version.rb,
lib/ztimer/watcher.rb,
lib/ztimer/sorted_store.rb
Defined Under Namespace
Classes: Slot, SortedStore, Watcher
Constant Summary collapse
- VERSION =
"0.5.0"
Class Attribute Summary collapse
-
.concurrency ⇒ Object
Returns the value of attribute concurrency.
-
.count ⇒ Object
readonly
Returns the value of attribute count.
-
.queue ⇒ Object
readonly
Returns the value of attribute queue.
-
.running ⇒ Object
readonly
Returns the value of attribute running.
-
.watcher ⇒ Object
readonly
Returns the value of attribute watcher.
Class Method Summary collapse
- .after(milliseconds, &callback) ⇒ Object
- .async(&callback) ⇒ Object
- .every(milliseconds, &callback) ⇒ Object
- .jobs_count ⇒ Object
- .stats ⇒ Object
Class Attribute Details
.concurrency ⇒ Object
Returns the value of attribute concurrency.
16 17 18 |
# File 'lib/ztimer.rb', line 16 def concurrency @concurrency end |
.count ⇒ Object (readonly)
Returns the value of attribute count.
16 17 18 |
# File 'lib/ztimer.rb', line 16 def count @count end |
.queue ⇒ Object (readonly)
Returns the value of attribute queue.
16 17 18 |
# File 'lib/ztimer.rb', line 16 def queue @queue end |
.running ⇒ Object (readonly)
Returns the value of attribute running.
16 17 18 |
# File 'lib/ztimer.rb', line 16 def running @running end |
.watcher ⇒ Object (readonly)
Returns the value of attribute watcher.
16 17 18 |
# File 'lib/ztimer.rb', line 16 def watcher @watcher end |
Class Method Details
.after(milliseconds, &callback) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/ztimer.rb', line 28 def after(milliseconds, &callback) enqueued_at = utc_microseconds expires_at = enqueued_at + milliseconds * 1000 slot = Slot.new(enqueued_at, expires_at, -1, &callback) add(slot) return slot end |
.async(&callback) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/ztimer.rb', line 18 def async(&callback) enqueued_at = utc_microseconds slot = Slot.new(enqueued_at, enqueued_at, -1, &callback) incr_counter! execute(slot) return slot end |
.every(milliseconds, &callback) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/ztimer.rb', line 38 def every(milliseconds, &callback) enqueued_at = utc_microseconds expires_at = enqueued_at + milliseconds * 1000 slot = Slot.new(enqueued_at, expires_at, milliseconds * 1000, &callback) add(slot) return slot end |
.jobs_count ⇒ Object
48 49 50 |
# File 'lib/ztimer.rb', line 48 def jobs_count return @watcher.jobs end |
.stats ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/ztimer.rb', line 58 def stats { running: @running, scheduled: @watcher.jobs, executing: @queue.size, total: @count } end |