Module: Farce::Abstract::Port Abstract
- Includes:
- Internal::Noncopyable, Shareable::Native, Shareable::Unfreezable, Internal::MarshalSupport::Reject
- Included in:
- Port, Strict::Port
- Defined in:
- lib/farce/abstract/port.rb
Overview
Common interface and ownership tracking for Farce ports.
This is a module so both implementations can inherit directly from the runtime's port backend.
Instance Method Summary collapse
-
#<< ⇒ self
Forwards all arguments to #send.
-
#close ⇒ self
Closes the port.
-
#closed? ⇒ Boolean
Whether the port is closed.
-
#owned? ⇒ Boolean
Checks whether the current Ractor created this port.
-
#pop ⇒ BasicObject?
Forwards all arguments to #receive.
-
#push ⇒ self
Forwards all arguments to #send.
-
#receive(timeout: nil) ⇒ BasicObject?
Waits for a message or the timeout.
-
#send(message) ⇒ self
Sends a message through the port.
Methods included from Shareable
Methods included from Internal::Noncopyable
Instance Method Details
#<< ⇒ self
Forwards all arguments to #send.
48 |
# File 'lib/farce/abstract/port.rb', line 48 def <<(...) = send(...) |
#close ⇒ self
Closes the port. Only the owning Ractor can close it.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/farce/abstract/port.rb', line 29 module Port include Internal::MarshalSupport::Reject include Internal::Noncopyable include Shareable::Native include Shareable::Unfreezable # @api private def initialize(...) # Native Ractor ports cannot hold Ruby instance variables. Internal::Storage.ractor[self] = true super end # Checks whether the current Ractor created this port. # @return [Boolean] whether the current Ractor owns the port def owned? = !!Internal::Storage.ractor[self] # Forwards all arguments to {#send}. # @return [self] def <<(...) = send(...) # Forwards all arguments to {#send}. # @return [self] def push(...) = send(...) # Forwards all arguments to {#receive}. # @return [BasicObject, nil] the received message, or nil on timeout def pop(...) = receive(...) # @api private def pretty_print(pp) string = inspect return pp.text(string) unless match = string.match(/\A#<([\w:]+)((?: \w+:#?\w+)+)>\z/) pp.group(1, "#<#{match[1]}", ">") do match[2].split.each do |pair| pp.breakable " " key, value = pair.split(":", 2) pp.text "#{key}:" pp.text value end end end end |
#closed? ⇒ Boolean
Returns whether the port is closed.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/farce/abstract/port.rb', line 29 module Port include Internal::MarshalSupport::Reject include Internal::Noncopyable include Shareable::Native include Shareable::Unfreezable # @api private def initialize(...) # Native Ractor ports cannot hold Ruby instance variables. Internal::Storage.ractor[self] = true super end # Checks whether the current Ractor created this port. # @return [Boolean] whether the current Ractor owns the port def owned? = !!Internal::Storage.ractor[self] # Forwards all arguments to {#send}. # @return [self] def <<(...) = send(...) # Forwards all arguments to {#send}. # @return [self] def push(...) = send(...) # Forwards all arguments to {#receive}. # @return [BasicObject, nil] the received message, or nil on timeout def pop(...) = receive(...) # @api private def pretty_print(pp) string = inspect return pp.text(string) unless match = string.match(/\A#<([\w:]+)((?: \w+:#?\w+)+)>\z/) pp.group(1, "#<#{match[1]}", ">") do match[2].split.each do |pair| pp.breakable " " key, value = pair.split(":", 2) pp.text "#{key}:" pp.text value end end end end |
#owned? ⇒ Boolean
Checks whether the current Ractor created this port.
44 |
# File 'lib/farce/abstract/port.rb', line 44 def owned? = !!Internal::Storage.ractor[self] |
#pop ⇒ BasicObject?
Forwards all arguments to #receive.
56 |
# File 'lib/farce/abstract/port.rb', line 56 def pop(...) = receive(...) |
#push ⇒ self
Forwards all arguments to #send.
52 |
# File 'lib/farce/abstract/port.rb', line 52 def push(...) = send(...) |
#receive(timeout: nil) ⇒ BasicObject?
Waits for a message or the timeout. Only the owning Ractor can receive.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/farce/abstract/port.rb', line 29 module Port include Internal::MarshalSupport::Reject include Internal::Noncopyable include Shareable::Native include Shareable::Unfreezable # @api private def initialize(...) # Native Ractor ports cannot hold Ruby instance variables. Internal::Storage.ractor[self] = true super end # Checks whether the current Ractor created this port. # @return [Boolean] whether the current Ractor owns the port def owned? = !!Internal::Storage.ractor[self] # Forwards all arguments to {#send}. # @return [self] def <<(...) = send(...) # Forwards all arguments to {#send}. # @return [self] def push(...) = send(...) # Forwards all arguments to {#receive}. # @return [BasicObject, nil] the received message, or nil on timeout def pop(...) = receive(...) # @api private def pretty_print(pp) string = inspect return pp.text(string) unless match = string.match(/\A#<([\w:]+)((?: \w+:#?\w+)+)>\z/) pp.group(1, "#<#{match[1]}", ">") do match[2].split.each do |pair| pp.breakable " " key, value = pair.split(":", 2) pp.text "#{key}:" pp.text value end end end end |
#send(message) ⇒ self
Sends a message through the port.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/farce/abstract/port.rb', line 29 module Port include Internal::MarshalSupport::Reject include Internal::Noncopyable include Shareable::Native include Shareable::Unfreezable # @api private def initialize(...) # Native Ractor ports cannot hold Ruby instance variables. Internal::Storage.ractor[self] = true super end # Checks whether the current Ractor created this port. # @return [Boolean] whether the current Ractor owns the port def owned? = !!Internal::Storage.ractor[self] # Forwards all arguments to {#send}. # @return [self] def <<(...) = send(...) # Forwards all arguments to {#send}. # @return [self] def push(...) = send(...) # Forwards all arguments to {#receive}. # @return [BasicObject, nil] the received message, or nil on timeout def pop(...) = receive(...) # @api private def pretty_print(pp) string = inspect return pp.text(string) unless match = string.match(/\A#<([\w:]+)((?: \w+:#?\w+)+)>\z/) pp.group(1, "#<#{match[1]}", ">") do match[2].split.each do |pair| pp.breakable " " key, value = pair.split(":", 2) pp.text "#{key}:" pp.text value end end end end |