Class: Range
- Inherits:
-
Object
- Object
- Range
- Defined in:
- lib/beanstalker/queue.rb,
lib/beanstalker/extend.rb
Constant Summary collapse
- DEFAULT_FANOUT_FUZZ =
0
- DEFAULT_FANOUT_DEGREE =
1000
Instance Method Summary collapse
- #async_each(rcv, selector, *extra) ⇒ Object
- #async_each_opts(rcv, selector, opts, *extra) ⇒ Object
- #rrepr ⇒ Object
- #size ⇒ Object
- #split_by(n) ⇒ Object
- #split_to(n) ⇒ Object
Instance Method Details
#async_each(rcv, selector, *extra) ⇒ Object
131 132 133 |
# File 'lib/beanstalker/extend.rb', line 131 def async_each(rcv, selector, *extra) async_each_opts(rcv, selector, {}, *extra) end |
#async_each_opts(rcv, selector, opts, *extra) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/beanstalker/extend.rb', line 115 def async_each_opts(rcv, selector, opts, *extra) fanout_degree = opts.fetch(:fanout_degree, DEFAULT_FANOUT_DEGREE) if size <= fanout_degree each {|i| rcv.async_send_opts(selector, opts, i, *extra)} else fanout_opts = opts.merge(:fuzz => opts.fetch(:fanout_fuzz, DEFAULT_FANOUT_FUZZ)) fanout_opts[:pri] = opts[:fanout_pri] || opts[:pri] fanout_opts = fanout_opts.reject{ |k,v| v.nil? } split_to(fanout_degree) do |subrange| subrange.async_send_opts(:async_each_opts, fanout_opts, rcv, selector, opts, *extra) end end end |
#rrepr ⇒ Object
178 |
# File 'lib/beanstalker/queue.rb', line 178 def rrepr() "(#{first.rrepr}#{exclude_end? ? '...' : '..'}#{last.rrepr})" end |
#size ⇒ Object
111 112 113 |
# File 'lib/beanstalker/extend.rb', line 111 def size last - first + (exclude_end? ? 0 : 1) end |
#split_by(n) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/beanstalker/extend.rb', line 100 def split_by(n) raise ArgumentError.new('invalid slice size') if n < 1 n -= 1 if !exclude_end? i = first while member?(i) j = [i + n, last].min yield(Range.new(i, j, exclude_end?)) i = j + (exclude_end? ? 0 : 1) end end |
#split_to(n) ⇒ Object
96 97 98 |
# File 'lib/beanstalker/extend.rb', line 96 def split_to(n) split_by((size + n - 1) / n) { |group| yield(group) } end |