Sha256: 18939ab9ab041efa360def9f2bd99856fd2342b0d8c0c3d7095aad7a9c30372e

Contents?: true

Size: 1.07 KB

Versions: 56

Compression:

Stored size: 1.07 KB

Contents

#--
# Copyright (C)2007-10 Tony Arcieri
# You can redistribute this under the terms of the Ruby license
# See file LICENSE for details
#++

module Coolio
  # The AsyncWatcher lets you signal another thread to wake up.  Its
  # intended use is notifying another thread of events.
  class AsyncWatcher < IOWatcher
    def initialize
      @reader, @writer = ::IO.pipe
      super(@reader)
    end

    # Signal the async watcher.  This call is thread safe.
    def signal
      # Write a byte to the pipe.  What we write is meaningless, it
      # merely signals an event has occurred for each byte written.
      @writer.write "\0"
    end

    # Called whenever a signal is received
    def on_signal; end
    event_callback :on_signal

    #########
    protected
    #########

    def on_readable
      # Read a byte from the pipe.  This clears readability, unless
      # another signal is pending
      begin
        @reader.read_nonblock 1
      rescue Errno::EAGAIN
        # in case there are spurious wakeups from forked processs
        return
      end
      on_signal
    end
  end
end

Version data entries

56 entries across 56 versions & 6 rubygems

Version Path
cool.io-1.9.0 lib/cool.io/async_watcher.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/lib/cool.io/async_watcher.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/lib/cool.io/async_watcher.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/lib/cool.io/async_watcher.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/lib/cool.io/async_watcher.rb
cool.io-1.8.0 lib/cool.io/async_watcher.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/cool.io-1.7.1/lib/cool.io/async_watcher.rb
cool.io-1.7.1-x86-mingw32 lib/cool.io/async_watcher.rb
cool.io-1.7.1-x64-mingw32 lib/cool.io/async_watcher.rb
cool.io-1.7.1 lib/cool.io/async_watcher.rb
cool.io-1.7.0 lib/cool.io/async_watcher.rb
cool.io-1.6.1 lib/cool.io/async_watcher.rb
cool.io-1.6.0-x64-mingw32 lib/cool.io/async_watcher.rb
cool.io-1.6.0-x86-mingw32 lib/cool.io/async_watcher.rb
cool.io-1.6.0 lib/cool.io/async_watcher.rb
cool.io-1.5.4-x64-mingw32 lib/cool.io/async_watcher.rb
cool.io-1.5.4-x86-mingw32 lib/cool.io/async_watcher.rb
cool.io-1.5.4 lib/cool.io/async_watcher.rb
cool.io-1.5.3-x86-mingw32 lib/cool.io/async_watcher.rb
cool.io-1.5.3-x64-mingw32 lib/cool.io/async_watcher.rb