Class: Range

Inherits:
Object
  • Object
show all
Defined in:
lib/async_observer/queue.rb,
lib/async_observer/extend.rb

Constant Summary collapse

DEFAULT_FANOUT_FUZZ =
0
DEFAULT_FANOUT_DEGREE =
1000

Instance Method Summary collapse

Instance Method Details

#async_each(rcv, selector, *extra) ⇒ Object



111
112
113
# File 'lib/async_observer/extend.rb', line 111

def async_each(rcv, selector, *extra)
  async_each_opts(rcv, selector, {}, *extra)
end

#async_each_opts(rcv, selector, opts, *extra) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/async_observer/extend.rb', line 95

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

#rreprObject



173
# File 'lib/async_observer/queue.rb', line 173

def rrepr() "(#{first.rrepr}#{exclude_end? ? '...' : '..'}#{last.rrepr})" end

#sizeObject



91
92
93
# File 'lib/async_observer/extend.rb', line 91

def size
  last - first + (exclude_end? ? 0 : 1)
end

#split_by(n) ⇒ Object

Raises:

  • (ArgumentError)


80
81
82
83
84
85
86
87
88
89
# File 'lib/async_observer/extend.rb', line 80

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



76
77
78
# File 'lib/async_observer/extend.rb', line 76

def split_to(n)
  split_by((size + n - 1) / n) { |group| yield(group) }
end