Class: Pwrake::Channel
- Inherits:
-
Object
- Object
- Pwrake::Channel
- Defined in:
- lib/pwrake/iomux/channel.rb
Instance Attribute Summary collapse
-
#fiber ⇒ Object
readonly
Returns the value of attribute fiber.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #finish ⇒ Object
- #get_line ⇒ Object
- #gets ⇒ Object
-
#initialize(handler, id = nil) ⇒ Channel
constructor
A new instance of Channel.
- #inspect ⇒ Object
- #ior ⇒ Object
- #put_line(line) ⇒ Object
- #puts(line) ⇒ Object
- #run_fiber(*args) ⇒ Object
Constructor Details
#initialize(handler, id = nil) ⇒ Channel
Returns a new instance of Channel.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/pwrake/iomux/channel.rb', line 5 def initialize(handler,id=nil) if @id = id @pre = "#{@id}:" else @pre = "" end if !handler.kind_of?(Handler) raise TypeError, "Argument must be Handler but #{handler.class}" end @handler = handler end |
Instance Attribute Details
#fiber ⇒ Object (readonly)
Returns the value of attribute fiber.
17 18 19 |
# File 'lib/pwrake/iomux/channel.rb', line 17 def fiber @fiber end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
17 18 19 |
# File 'lib/pwrake/iomux/channel.rb', line 17 def handler @handler end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
17 18 19 |
# File 'lib/pwrake/iomux/channel.rb', line 17 def id @id end |
Instance Method Details
#finish ⇒ Object
34 35 36 37 38 |
# File 'lib/pwrake/iomux/channel.rb', line 34 def finish if !@fiber.nil? @fiber.resume(nil) end end |
#get_line ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/pwrake/iomux/channel.rb', line 40 def get_line @handler.add_channel(self) @fiber = Fiber.current line = Fiber.yield @fiber = nil @handler.delete_channel(self) return line end |
#gets ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/pwrake/iomux/channel.rb', line 57 def gets if @id raise RuntimeError,"gets is invalid when @id is non-nil" else @handler.gets end end |
#inspect ⇒ Object
65 66 67 |
# File 'lib/pwrake/iomux/channel.rb', line 65 def inspect "#<#{self.class} io=#{ior.inspect} id=#{id.inspect}>" end |
#ior ⇒ Object
19 20 21 |
# File 'lib/pwrake/iomux/channel.rb', line 19 def ior @handler.ior end |
#put_line(line) ⇒ Object
49 50 51 |
# File 'lib/pwrake/iomux/channel.rb', line 49 def put_line(line) @handler.put_line "#{@pre}#{line}" end |
#puts(line) ⇒ Object
53 54 55 |
# File 'lib/pwrake/iomux/channel.rb', line 53 def puts(line) @handler.puts "#{@pre}#{line}" end |
#run_fiber(*args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pwrake/iomux/channel.rb', line 23 def run_fiber(*args) if @fiber.nil? m = "Channel#run_fiber: @fiber is nil,"+ " args=#{args.inspect} @id=#{@id}" $stderr.puts m Log.debug m else @fiber.resume(*args) end end |