class LSync::Timeout
Manages a callback that will be executed after a set duration.
Attributes
thread[R]
The thread on which the timeout is being waited.
Public Class Methods
new(timeout) { || ... }
click to toggle source
# File lib/lsync/event_timer.rb, line 27 def initialize(timeout, &block) @cancelled = false @thread = Thread.new do sleep timeout unless @cancelled yield end end end
Public Instance Methods
cancel!()
click to toggle source
Cancel the timeout if possible and ensure that the callback is not executed.
# File lib/lsync/event_timer.rb, line 43 def cancel! @cancelled = true @thread.exit end