Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
Created August 9, 2013 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnunemaker/6196418 to your computer and use it in GitHub Desktop.
Save jnunemaker/6196418 to your computer and use it in GitHub Desktop.
Kestrel blocking client with signal checks for the kestrel-client gem.
module Kestrel
class Client
class BlockingWithCheck < Blocking
attr_accessor :return_check
def get(*args)
count = 0
while count += 1
if response = client.get(*args)
return response
end
sleep_for_count(count)
if @return_check
return if @return_check.call
end
end
end
end
end
end
require 'spec_helper'
require 'kestrel/client/blocking_with_check'
describe Kestrel::Client::BlockingWithCheck do
let(:client) { Kestrel::Client.new }
subject {
described_class.new(client)
}
before do
client.stub(:get => nil)
end
it "blocks if return check is false" do
subject.return_check = proc { false }
client.should_receive(:get).with(:foo).exactly(3).times.and_return(nil, nil, 'woot')
Timeout.timeout(0.05) do
subject.get(:foo).should eq('woot')
end
end
it "returns if check is true" do
subject.return_check = proc { true }
Timeout.timeout(0.05) do
subject.get(:foo)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment