Class: Farce::Strict::Publisher

Inherits:
Abstract::Publisher
  • Object
show all
Includes:
Farce::Shareable::Unfreezable
Defined in:
lib/farce/strict/publisher.rb

Overview

Strict variant of Publisher.

Instance Method Summary collapse

Methods included from Farce::Shareable

#ractor_shareable?

Constructor Details

#initialize(*subscribers) ⇒ Publisher

Returns a new instance of Publisher.



13
14
15
16
17
# File 'lib/farce/strict/publisher.rb', line 13

def initialize(*subscribers)
  @map = Strict::Map.new
  super()
  subscribers.each { subscribe(it) }
end

Instance Method Details

#publish(message = nil) ⇒ self Also known as: send, <<, broadcast

Publishes the given payload to all current subscribers.

Full bounded queues drop new messages. Failed publishing attempts to closed or frozen receivers cancel their subscriptions.

Parameters:

  • payload (BasicObject) —

    the payload to publish

Returns:

  • (self) —

    the publisher itself



20
21
22
23
# File 'lib/farce/strict/publisher.rb', line 20

def publish(message = nil)
  return super if Ractor.shareable?(message)
  raise Ractor::IsolationError, "value must be Ractor-shareable"
end