Class: Fairy::PWideInject

Inherits:
PInject show all
Defined in:
lib/fairy/node/p-inject.rb

Constant Summary

Constants inherited from PIOFilter

Fairy::PIOFilter::ST_WAIT_IMPORT

Constants inherited from PFilter

Fairy::PFilter::END_OF_STREAM, Fairy::PFilter::ST_ACTIVATE, Fairy::PFilter::ST_FINISH, Fairy::PFilter::ST_INIT

Instance Attribute Summary

Attributes inherited from PFilter

#IGNORE_EXCEPTION, #id, #log_id, #ntask

Instance Method Summary collapse

Methods inherited from PFilter

#abort_running, #basic_start, #break_running, #global_break, #global_break_from_other, #handle_exception, #key, #key=, #next, #no, #no=, #notice_status, #processor, #start, #start_export, #start_watch_status, #status=, #terminate, #terminate_proc

Constructor Details

#initialize(*args) ⇒ PWideInject

Returns a new instance of PWideInject.



71
72
73
74
75
76
77
# File 'lib/fairy/node/p-inject.rb', line 71

def initialize(*args)
  super

  @value = :__FAIRY_NO_VALUE__
  @value_mutex = Mutex.new
  @value_cv = XThread::ConditionVariable.new
end

Instance Method Details

#basic_each(&block) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/fairy/node/p-inject.rb', line 89

def basic_each(&block)
  @inject_proc = BBlock.new(@block_source, @context, self)
  sum = @init_value
  @input.sort_by{|n, e| n}.each do |n, e|
#Log::debug(self, "n e: #{n}, #{e}")
  if sum == :__FAIRY_NO_VALUE__
    sum = e
  else
    if Import::CTLTOKEN_NULLVALUE === (v = @inject_proc.yield(sum, e))
 next
    end
    sum = v
  end
  end
  finish(sum, &block)
end

#each(&block) ⇒ Object



106
107
108
# File 'lib/fairy/node/p-inject.rb', line 106

def each(&block)
  block.call value
end

#finish(sum, &block) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/fairy/node/p-inject.rb', line 120

def finish(sum, &block)
  @value = sum
  @value_cv.broadcast 
  if block
  block.call sum
  end
end

#input=(input) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/fairy/node/p-inject.rb', line 79

def input=(input)
  super

  start do
  self.super_each{}
  end
end

#super_eachObject



87
# File 'lib/fairy/node/p-inject.rb', line 87

alias super_each each

#valueObject



110
111
112
113
114
115
116
117
# File 'lib/fairy/node/p-inject.rb', line 110

def value
  @value_mutex.synchronize do
  while @value == :__FAIRY_NO_VALUE__
    @value_cv.wait(@value_mutex)
  end
  @value
  end
end