Class: Concurrent::ProcessingActor
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Concurrent::Synchronization::Object
|
Defined in: | lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb |
Overview
**Edge Features** are under active development and may change frequently.
-
Deprecations are not added before incompatible changes.
-
Edge
version: major is always 0, minor bump means incompatible change, patch bump means compatible change. -
Edge
features may also lack tests and documentation. -
Features developed in
concurrent-ruby-edge
are expected to move toconcurrent-ruby
when finalised.
A new implementation of actor which also simulates the process, therefore it can be used in the same way as Erlang’s actors but without occupying thread. A tens of thousands ProcessingActors can run at the same time sharing a thread pool.
Class Attribute Summary
Synchronization::Object
- Inherited
Class Method Summary
-
.act(*args, &process) ⇒ ProcessingActor
Creates an actor.
-
.act_listening(channel, *args) {|actor, *args| ... } ⇒ ProcessingActor
Creates an actor listening to a specified channel (mailbox).
- .new(channel, *args, &process) ⇒ ProcessingActor constructor private
Synchronization::Object
- Inherited
.atomic_attribute?, .atomic_attributes, | |
.attr_atomic | Creates methods for reading and writing to a instance variable with volatile (Java) semantic as |
.attr_volatile | Creates methods for reading and writing (as |
.ensure_safe_initialization_when_final_fields_are_present | For testing purposes, quite slow. |
.new | Has to be called by children. |
.safe_initialization!, .define_initialize_atomic_fields |
Synchronization::AbstractObject
- Inherited
Instance Method Summary
-
#ask_op(answer = Promises.resolvable_future, &message_provider)
actor.ask2 { |a| [:count, a] }
-
#inspect
Alias for #to_s.
- #mailbox ⇒ Promises::Channel
-
#receive(channel = mailbox)
Receives a message when available, used in the actor’s process.
-
#tell!(message) ⇒ self
Tells a message to the actor.
-
#tell_op(message) ⇒ Promises::Future(ProcessingActor)
Tells a message to the actor.
- #termination ⇒ Promises::Future(Object)
- #to_ary
- #to_s ⇒ String (also: #inspect)
Synchronization::Object
- Inherited
Synchronization::Volatile
- Included
Synchronization::AbstractObject
- Inherited
Constructor Details
.new(channel, *args, &process) ⇒ ProcessingActor
(private)
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 177
def initialize(channel, *args, &process) @Mailbox = channel @Terminated = Promises.future(self, *args, &process).run super() end
Class Method Details
.act(*args, &process) ⇒ ProcessingActor
Creates an actor.
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 54
def self.act(*args, &process) act_listening Promises::Channel.new, *args, &process end
.act_listening(channel, *args) {|actor, *args| ... } ⇒ ProcessingActor
Creates an actor listening to a specified channel (mailbox).
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 67
def self.act_listening(channel, *args, &process) ProcessingActor.new channel, *args, &process end
Instance Method Details
#ask_op(answer = Promises.resolvable_future, &message_provider)
actor.ask2 { |a| [:count, a] }
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 157
def ask_op(answer = Promises.resolvable_future, & ) # TODO (pitr-ch 12-Dec-2018): is it ok to let the answers be unanswered when the actor terminates tell_op( .call(answer)).then(answer) { |_, a| a } # answer.chain { |v| [true, v] } | @Terminated.then end
#inspect
Alias for #to_s.
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 169
alias_method :inspect, :to_s
#mailbox ⇒ Promises::Channel
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 29
def mailbox @Mailbox end
#receive(channel = mailbox)
Receives a message when available, used in the actor’s process.
@return [Promises::Future(Object)] a future which will be fulfilled with a message from
mailbox when it is available.
def receive(*channels)
channels = [@Mailbox] if channels.empty?
Promises::Channel.select(*channels)
# TODO (pitr-ch 27-Dec-2016): support patterns
# - put any received message aside if it does not match
# - on each receive call check the messages put aside
# - track where the message came from, cannot later receive m form other channel only because it matches
end
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 83
def receive(channel = mailbox) channel.pop_op end
#tell!(message) ⇒ self
Tells a message to the actor. May block current thread if the mailbox is full. #tell_op is a better option since it does not block. It’s usually used to integrate with threading code.
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 99
def tell!( ) @Mailbox.push( ) self end
#tell_op(message) ⇒ Promises::Future(ProcessingActor
)
Tells a message to the actor.
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 108
def tell_op( ) @Mailbox.push_op( ).then(self) { |_ch, actor| actor } end
#termination ⇒ Promises::Future(Object)
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 36
def termination @Terminated.with_hidden_resolvable end
#to_ary
[ GitHub ]# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 171
def to_ary [@Mailbox, @Terminated] end
#to_s ⇒ String
Also known as: #inspect
# File 'lib/concurrent-ruby-edge/concurrent/edge/processing_actor.rb', line 165
def to_s format '%s termination: %s>', super[0..-2], termination.state end