1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Allocate Chain entries lazily

This commit is contained in:
fatkodima 2019-09-14 17:37:45 +03:00 committed by Mike Perham
parent 705d6ca7ea
commit de03df4160

View file

@ -67,7 +67,6 @@ module Sidekiq
module Middleware
class Chain
include Enumerable
attr_reader :entries
def initialize_copy(copy)
copy.instance_variable_set(:@entries, entries.dup)
@ -78,10 +77,14 @@ module Sidekiq
end
def initialize
@entries = []
@entries = nil
yield self if block_given?
end
def entries
@entries ||= []
end
def remove(klass)
entries.delete_if { |entry| entry.klass == klass }
end
@ -114,6 +117,10 @@ module Sidekiq
any? { |entry| entry.klass == klass }
end
def empty?
@entries.nil? || @entries.empty?
end
def retrieve
map(&:make_new)
end
@ -123,6 +130,8 @@ module Sidekiq
end
def invoke(*args)
return yield if empty?
chain = retrieve.dup
traverse_chain = lambda do
if chain.empty?