Sha256: e1e2a8f5934f9b5d2d51c54da7c88d41aff71817a69f47b8b215b1edbf45abf6

Contents?: true

Size: 508 Bytes

Versions: 9

Compression:

Stored size: 508 Bytes

Contents

# frozen_string_literal: true

module Polyphony
  # Event watcher for thread-safe synchronisation
  class Event
    def initialize
      @i, @o = IO.pipe
    end

    def await
      Thread.current.agent.read(@i, +'', 8192, false)
      raise @value if @value.is_a?(Exception)

      @value
    end

    def await_no_raise
      Thread.current.agent.read(@i, +'', 8192, false)
      @value
    end

    def signal(value = nil)
      @value = value
      Thread.current.agent.write(@o, '1')
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
polyphony-0.43.6 lib/polyphony/event.rb
polyphony-0.43.5 lib/polyphony/event.rb
polyphony-0.43.4 lib/polyphony/event.rb
polyphony-0.43.3 lib/polyphony/event.rb
polyphony-0.43.2 lib/polyphony/event.rb
polyphony-0.43.1 lib/polyphony/event.rb
polyphony-0.43 lib/polyphony/event.rb
polyphony-0.42 lib/polyphony/event.rb
polyphony-0.41 lib/polyphony/event.rb