Class: CRuby::TimerChannel

Inherits:
Channel
  • Object
show all
Includes:
IOT
Defined in:
lib/cruby/channel.rb

Instance Method Summary collapse

Methods included from IOT

exec, input, output

Methods inherited from Channel

#initialize, #recv, #recvEvt, #send

Constructor Details

This class inherits a constructor from CRuby::Channel

Instance Method Details

#sendEvt(msg) ⇒ Object

送信イベントを生成する



167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/cruby/channel.rb', line 167

def sendEvt msg
  pollFn = Proc.new { false }
  blockFn = Proc.new {|flg,k|
    if flg[0] == true then
      CRuby::Coroutine.dispatch
    end
    @@timerQ <<= {:time=>Time.now+msg,:chan=>self}
    @@timerQ.sort! {|a,b| a[:time]<=>b[:time]}
    @sendQ.enqueue({'flg'=>flg,'msg'=>msg,'cont'=>k})
  }
  CRuby::Event.new([CRuby::Event::BEvt.new(pollFn, nil, blockFn)])
end

#timeoutObject



180
181
182
183
184
# File 'lib/cruby/channel.rb', line 180

def timeout
  item = @sendQ.dequeue
  item['flg'][0] = true
  CRuby::Coroutine.enqueue(item['cont'])
end