Class: Async::Timeout
- Inherits:
-
Object
- Object
- Async::Timeout
- Defined in:
- lib/async/timeout.rb
Overview
Represents a flexible timeout that can be rescheduled or extended.
Defined Under Namespace
Classes: CancelledError
Instance Method Summary collapse
-
#adjust(duration) ⇒ Object
Adjust the timeout by the specified duration.
-
#cancel! ⇒ Object
Cancel the timeout, preventing it from executing.
- #cancelled? ⇒ Boolean
- #duration ⇒ Object
-
#duration=(value) ⇒ Object
Update the duration of the timeout.
-
#initialize(timers, handle) ⇒ Timeout
constructor
Initialize a new timeout.
- #now ⇒ Object
- #time ⇒ Object
-
#time=(value) ⇒ Object
Assign a new time to the timeout, rescheduling it if necessary.
Constructor Details
#initialize(timers, handle) ⇒ Timeout
Initialize a new timeout.
11 12 13 14 |
# File 'lib/async/timeout.rb', line 11 def initialize(timers, handle) @timers = timers @handle = handle end |
Instance Method Details
#adjust(duration) ⇒ Object
Adjust the timeout by the specified duration.
The duration is relative to the timeout time, e.g. adjusting the timeout by 5 increases the current duration by 5 seconds.
36 37 38 |
# File 'lib/async/timeout.rb', line 36 def adjust(duration) self.reschedule(time + duration) end |
#cancel! ⇒ Object
Cancel the timeout, preventing it from executing.
59 60 61 |
# File 'lib/async/timeout.rb', line 59 def cancel! @handle.cancel! end |
#cancelled? ⇒ Boolean
64 65 66 |
# File 'lib/async/timeout.rb', line 64 def cancelled? @handle.cancelled? end |
#duration ⇒ Object
17 18 19 |
# File 'lib/async/timeout.rb', line 17 def duration @handle.time - @timers.now end |
#duration=(value) ⇒ Object
Update the duration of the timeout.
The duration is relative to the current time, e.g. setting the duration to 5 means the timeout will occur in 5 seconds from now.
26 27 28 |
# File 'lib/async/timeout.rb', line 26 def duration=(value) self.reschedule(@timers.now + value) end |
#now ⇒ Object
54 55 56 |
# File 'lib/async/timeout.rb', line 54 def now @timers.now end |
#time ⇒ Object
41 42 43 |
# File 'lib/async/timeout.rb', line 41 def time @handle.time end |
#time=(value) ⇒ Object
Assign a new time to the timeout, rescheduling it if necessary.
49 50 51 |
# File 'lib/async/timeout.rb', line 49 def time=(value) self.reschedule(value) end |