Sha256: c595809e88bd3c2a49a62794da0993057c5dbb97238432628f67a8daff3cbe78

Contents?: true

Size: 959 Bytes

Versions: 3

Compression:

Stored size: 959 Bytes

Contents

# -*- encoding: binary -*-
# :enddoc:
module Rainbows::Fiber::Coolio::Methods
  class Watcher < Coolio::IOWatcher
    def initialize(fio, flag)
      @f = Fiber.current
      super(fio, flag)
      attach(Coolio::Loop.default)
    end

    def on_readable
      @f.resume
    end

    alias on_writable on_readable
  end

  def close
    @w.detach if defined?(@w) && @w.attached?
    @r.detach if defined?(@r) && @r.attached?
    super
  end

  def kgio_wait_writable
    @w = Watcher.new(self, :w) unless defined?(@w)
    @w.enable unless @w.enabled?
    Fiber.yield
    @w.disable
  end

  def kgio_wait_readable
    @r = Watcher.new(self, :r) unless defined?(@r)
    @r.enable unless @r.enabled?
    Fiber.yield
    @r.disable
  end
end

[
  Rainbows::Fiber::IO,
  # the next two trigger autoload, ugh, oh well...
  Rainbows::Fiber::IO::Socket,
  Rainbows::Fiber::IO::Pipe
].each do |klass|
  klass.__send__(:include, Rainbows::Fiber::Coolio::Methods)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rainbows-4.0.0 lib/rainbows/fiber/coolio/methods.rb
rainbows-3.4.0 lib/rainbows/fiber/coolio/methods.rb
rainbows-3.3.0 lib/rainbows/fiber/coolio/methods.rb