Class: Fibril::ForkedNonBlockingIOWrapper
- Inherits:
-
NonBlockingIOWrapper
- Object
- NonBlockingIOWrapper
- Fibril::ForkedNonBlockingIOWrapper
- Defined in:
- lib/fibril/forked_non_blocking_io_wrapper.rb
Instance Attribute Summary collapse
-
#read ⇒ Object
Returns the value of attribute read.
-
#write ⇒ Object
Returns the value of attribute write.
Attributes inherited from NonBlockingIOWrapper
#fibrils, #guard, #response_queue, #result
Instance Method Summary collapse
- #freceive(*args) ⇒ Object
-
#initialize(&block) ⇒ ForkedNonBlockingIOWrapper
constructor
A new instance of ForkedNonBlockingIOWrapper.
- #receive(*args) ⇒ Object
- #start ⇒ Object
Methods inherited from NonBlockingIOWrapper
Constructor Details
#initialize(&block) ⇒ ForkedNonBlockingIOWrapper
Returns a new instance of ForkedNonBlockingIOWrapper.
7 8 9 10 11 12 13 |
# File 'lib/fibril/forked_non_blocking_io_wrapper.rb', line 7 def initialize(*, &block) read, write = IO.pipe self.read, self.write = read, write self.response_queue = [] self.fibrils = [] define_singleton_method(:loop, &block) end |
Instance Attribute Details
#read ⇒ Object
Returns the value of attribute read.
4 5 6 |
# File 'lib/fibril/forked_non_blocking_io_wrapper.rb', line 4 def read @read end |
#write ⇒ Object
Returns the value of attribute write.
4 5 6 |
# File 'lib/fibril/forked_non_blocking_io_wrapper.rb', line 4 def write @write end |
Instance Method Details
#freceive(*args) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/fibril/forked_non_blocking_io_wrapper.rb', line 44 def freceive(*args) if args.any? ingest(*args) else method(:ingest) end end |
#receive(*args) ⇒ Object
40 41 42 |
# File 'lib/fibril/forked_non_blocking_io_wrapper.rb', line 40 def receive(*args) self.write.puts URI.escape(Marshal.dump(args)) rescue nil end |
#start ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fibril/forked_non_blocking_io_wrapper.rb', line 15 def start freceive = method(:freceive) block = method(:loop) read, write = self.read, self.write fibril{ fork do read.close block[] exit(0) end write.close begin Fibril.current.tick while = read.gets freceive[*Marshal.load(URI.unescape())] Fibril.current.tick end rescue Exception => e puts "Exception! : #{e}" puts e.backtrace end } end |