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.



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

def initialize(*args)
  super

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

Instance Method Details

#basic_each(&block) ⇒ Object



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

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



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

def each(&block)
  block.call value
end

#finish(sum, &block) ⇒ Object



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

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

#input=(input) ⇒ Object



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

def input=(input)
  super

  start do
	self.super_each{}
  end
end

#super_eachObject



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

alias super_each each

#valueObject



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

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