Class: Throttler::Throttle
- Inherits:
-
Object
- Object
- Throttler::Throttle
- Defined in:
- lib/throttler/throttle.rb
Class Attribute Summary collapse
-
.tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
Instance Method Summary collapse
- #hold(wait) ⇒ Object
-
#initialize(namespace) ⇒ Throttle
constructor
A new instance of Throttle.
- #release ⇒ Object
- #strangle ⇒ Object
Constructor Details
#initialize(namespace) ⇒ Throttle
Returns a new instance of Throttle.
9 10 11 |
# File 'lib/throttler/throttle.rb', line 9 def initialize(namespace) @namespace = namespace end |
Class Attribute Details
.tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
4 5 6 |
# File 'lib/throttler/throttle.rb', line 4 def tmp_dir @tmp_dir end |
Instance Method Details
#hold(wait) ⇒ Object
13 14 15 16 |
# File 'lib/throttler/throttle.rb', line 13 def hold(wait) sleep [ + wait - now, 0.0].max end |
#release ⇒ Object
18 19 20 21 |
# File 'lib/throttler/throttle.rb', line 18 def release @file.flock File::LOCK_UN @file.close end |
#strangle ⇒ Object
23 24 25 |
# File 'lib/throttler/throttle.rb', line 23 def strangle file.flock File::LOCK_EX end |