Skip to content

Commit b40161f

Browse files
author
Aaron Patterson and Terence Lee
committed
create a SizedStack for the connection pool
1 parent 5b86880 commit b40161f

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

lib/resque.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require 'resque/consumer'
2020
require 'resque/threaded_pool'
2121
require 'resque/connection_pool'
22+
require 'resque/sized_stack'
2223

2324
require 'resque/vendor/utf8_util'
2425

lib/resque/sized_stack.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'thread'
2+
3+
module Resque
4+
###
5+
# Sized LIFO queue.
6+
class SizedStack < SizedQueue
7+
def initialize(size)
8+
super
9+
class << @que
10+
alias :shift :pop
11+
end
12+
end
13+
end
14+
end

test/sized_stack_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require "test_helper"
2+
3+
module Resque
4+
describe SizedStack do
5+
it "can be constructed" do
6+
assert Resque::SizedStack.new(10)
7+
end
8+
9+
it "pops off what we push" do
10+
stack = Resque::SizedStack.new 10
11+
thing = Object.new
12+
stack.push thing
13+
assert_equal thing, stack.pop
14+
end
15+
16+
it "is a stack" do
17+
stack = Resque::SizedStack.new 10
18+
items = 10.times.map { Object.new }
19+
items.each { |i| stack << i }
20+
items.reverse_each do |i|
21+
assert_equal i, stack.pop
22+
end
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)