Method: RMX#debounce_runloop

Defined in:
lib/motion/util.rb

#debounce_runloop(unique_id, run_immediately = false, &block) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/motion/util.rb', line 102

def debounce_runloop(unique_id, run_immediately=false, &block)
  if object = unsafe_unretained_object
    lookup = Thread.current["rmx_debounce_runloop"] ||= {}
    key = [ object, unique_id ]
    lookup[key] ||= begin
      block.call if run_immediately
      CFRunLoopPerformBlock(
        CFRunLoopGetCurrent(),
        KCFRunLoopDefaultMode,
        lambda do
          lookup.delete(key)
          block.call
        end
      )
      true
    end
    nil
  end
end