Skip to content

Instantly share code, notes, and snippets.

@ncr
Created April 3, 2011 17:32
Show Gist options
  • Save ncr/900591 to your computer and use it in GitHub Desktop.
Save ncr/900591 to your computer and use it in GitHub Desktop.
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