Class: Throttler::Throttle

Inherits:
Object
  • Object
show all
Defined in:
lib/throttler/throttle.rb

Class Attribute Summary collapse

Instance Method Summary collapse

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_dirObject

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 [timestamp + wait - now, 0.0].max
  timestamp!
end

#releaseObject



18
19
20
21
# File 'lib/throttler/throttle.rb', line 18

def release
  @file.flock File::LOCK_UN
  @file.close
end

#strangleObject



23
24
25
# File 'lib/throttler/throttle.rb', line 23

def strangle
  file.flock File::LOCK_EX
end