Class: Timers::Events::Handle

### Home Classes Methods

### In Files

- lib/timers/events.rb

### Parent

Object

### Methods

- ::new
- #>
- #cancel!
- #cancelled?
- #fire
- #to_f

### Class/Module Index

Quicksearch

- Timers
- Timers::Events
- Timers::Events::Handle
- Timers::Group
- Timers::Timer
- Timers::Wait

No matching classes.

# Timers::Events::Handle

Represents a cancellable handle for a specific timer event.

### Attributes

time[R]

The absolute time that the handle should be fired at.

### Public Class Methods

new(time, callback) click to toggle source

    # File lib/timers/events.rb, line 12
    def initialize(time, callback)
      @time = time
      @callback = callback
    end

### Public Instance Methods

>(other) click to toggle source

    # File lib/timers/events.rb, line 32
    def > other
      @time > other.to_f
    end

cancel!() click to toggle source

Cancel this timer, O(1).

    # File lib/timers/events.rb, line 21
    def cancel!
      # The simplest way to keep track of cancelled status is to nullify the
      # callback. This should also be optimal for garbage collection.
      @callback = nil
    end

cancelled?() click to toggle source

Has this timer been cancelled? Cancelled timer's don't fire.

    # File lib/timers/events.rb, line 28
    def cancelled?
      @callback.nil?
    end

fire(time) click to toggle source

Fire the callback if not cancelled with the given time parameter.

    # File lib/timers/events.rb, line 41
    def fire(time)
      if @callback
        @callback.call(time)
      end
    end

to_f() click to toggle source

    # File lib/timers/events.rb, line 36
    def to_f
      @time
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.