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



84
85
86
# File 'lib/async_observer/extend.rb', line 84

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

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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/async_observer/extend.rb', line 68

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_hash{|k,v| nil.equal?(v)}
    split_to(fanout_degree) do |subrange|
      subrange.async_send_opts(:async_each_opts, fanout_opts, rcv, selector,
                               opts, *extra)
    end
  end
end

#rreprObject



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

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

#sizeObject



64
65
66
# File 'lib/async_observer/extend.rb', line 64

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

#split_by(n) ⇒ Object

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
62
# File 'lib/async_observer/extend.rb', line 53

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



49
50
51
# File 'lib/async_observer/extend.rb', line 49

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