Skip to content

Commit

Permalink
Don't yield the block on timeouts.
Browse files Browse the repository at this point in the history
  • Loading branch information
djanowski committed Mar 20, 2012
1 parent 1afba24 commit fc1a609
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ost.rb
Expand Up @@ -25,6 +25,8 @@ def each(&block)


item = @key.brpoplpush(@backup, TIMEOUT) item = @key.brpoplpush(@backup, TIMEOUT)


next unless item

block.call(item) block.call(item)


@backup.lpop @backup.lpop
Expand Down
16 changes: 16 additions & 0 deletions test/ost_test.rb
Expand Up @@ -53,6 +53,22 @@ def enqueue(id)
assert_equal ["1"], results assert_equal ["1"], results
end 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 test "halt processing a queue" do
Thread.new do Thread.new do
sleep 0.5 sleep 0.5
Expand Down

0 comments on commit fc1a609

Please sign in to comment.