diff --git a/lib/ost.rb b/lib/ost.rb index 8e944f2..db2b4d2 100644 --- a/lib/ost.rb +++ b/lib/ost.rb @@ -25,6 +25,8 @@ def each(&block) item = @key.brpoplpush(@backup, TIMEOUT) + next unless item + block.call(item) @backup.lpop diff --git a/test/ost_test.rb b/test/ost_test.rb index 35597dc..e0fbb28 100644 --- a/test/ost_test.rb +++ b/test/ost_test.rb @@ -53,6 +53,22 @@ def enqueue(id) assert_equal ["1"], results end + test "doesn't yield the block on timeout" do |redis| + results = [] + + Thread.new do + sleep 2 + enqueue(1) + end + + ost do |item| + results << item + end + + assert_equal [], Ost[:events].items + assert_equal ["1"], results + end + test "halt processing a queue" do Thread.new do sleep 0.5