Skip to content

Instantly share code, notes, and snippets.

@ncr

ncr/choke.rb

Created Apr 3, 2011
Embed
What would you like to do?
class Choke
def initialize(interval)
@interval = interval
@mutex = Mutex.new
end
def perform
thread, result = nil, nil
@mutex.synchronize do
thread = Thread.new { result = yield }
sleep(@interval)
end
thread.join
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment