Module: Svent::EventManger::Helper
- Defined in:
- lib/svent/event_manger.rb
Class Attribute Summary collapse
-
.this ⇒ Object
writeonly
Sets the attribute this.
Class Method Summary collapse
- .after_delete ⇒ Object
- .delete ⇒ Object
- .filter(&block) ⇒ Object
- .init(events, callback_fibers) ⇒ Object
- .loop(condition, info = nil, &block) ⇒ Object
- .ok?(info = nil, &block) ⇒ Boolean
- .times(value) ⇒ Object
- .times_filter(value) ⇒ Object
- .wait(value) ⇒ Object
- .wait_filter(value) ⇒ Object
Class Attribute Details
.this=(value) ⇒ Object (writeonly)
Sets the attribute this
12 13 14 |
# File 'lib/svent/event_manger.rb', line 12 def this=(value) @this = value end |
Class Method Details
.after_delete ⇒ Object
24 25 26 |
# File 'lib/svent/event_manger.rb', line 24 def after_delete @events[@this.name].delete(@this.callback) end |
.delete ⇒ Object
28 29 30 31 |
# File 'lib/svent/event_manger.rb', line 28 def delete after_delete Fiber.yield true end |
.filter(&block) ⇒ Object
48 49 50 |
# File 'lib/svent/event_manger.rb', line 48 def filter(&block) Fiber.yield true unless block.call end |
.init(events, callback_fibers) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/svent/event_manger.rb', line 14 def init(events, callback_fibers) @this = nil @events = events @callback_fibers = callback_fibers @timers = {} @counters = {} @timer_filters = {} @counter_filters = {} end |
.loop(condition, info = nil, &block) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/svent/event_manger.rb', line 40 def loop(condition, info = nil, &block) Kernel.loop do break if condition.call block.call(info) Fiber.yield end end |
.ok?(info = nil, &block) ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/svent/event_manger.rb', line 33 def ok?(info = nil, &block) Kernel.loop do break if block.call(info) Fiber.yield end end |
.times(value) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/svent/event_manger.rb', line 61 def times(value) counter = @counters[@this.object_id] counter ? @counters[@this.object_id] += 1 : @counters[@this.object_id] = 1 loop do break @counters.delete(@this.object_id) if counter > value Fiber.yield end end |
.times_filter(value) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/svent/event_manger.rb', line 79 def times_filter(value) counter_filter = @counter_filters[@this.object_id] counter_filter ? @counter_filters[@this.object_id] += 1 : (return @counter_filters[@this.object_id] = 1) loop do break @counter_filters.delete(@this.object_id) if @counter_filters[object_id] > value Fiber.yield true end end |
.wait(value) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/svent/event_manger.rb', line 52 def wait(value) timer = @timers[@this.object_id] timer = Time.now unless timer loop do break @timers.delete(@this.object_id) unless Time.now - timer < value Fiber.yield end end |
.wait_filter(value) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/svent/event_manger.rb', line 70 def wait_filter(value) timer_filter = @timer_filters[@this.object_id] return timer_filter = Time.now unless timer_filter loop do break @timer_filters.delete(@this.object_id) unless Time.now - timer_filter < value Fiber.yield true end end |