Module: Concurrent::Actress

Defined in:
lib/concurrent/actress.rb,
lib/concurrent/actress/core.rb,
lib/concurrent/actress/ad_hoc.rb,
lib/concurrent/actress/errors.rb,
lib/concurrent/actress/context.rb,
lib/concurrent/actress/envelope.rb,
lib/concurrent/actress/reference.rb,
lib/concurrent/actress/type_check.rb,
lib/concurrent/actress/core_delegations.rb

Overview

Defined Under Namespace

Modules: Context, CoreDelegations, TypeCheck Classes: ActressTerminated, AdHoc, Core, Envelope, Reference, Root

Constant Summary collapse

ROOT =

A root actor, a default parent of all actors spawned outside an actor

Core.new(parent: nil, name: '/', class: Root).reference
Error =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.currentReference?

Returns current executing actor if any.

Returns:

  • (Reference, nil)

    current executing actor if any



22
23
24
# File 'lib/concurrent/actress.rb', line 22

def self.current
  Thread.current[:__current_actress__]
end

.spawn(*args, &block) ⇒ Object

Parameters:



44
45
46
47
48
49
50
51
# File 'lib/concurrent/actress.rb', line 44

def self.spawn(*args, &block)
  warn '[EXPERIMENTAL] A full release of `Actress`, renamed `Actor`, is expected in the 0.7.0 release.'
  if Actress.current
    Core.new(spawn_optionify(*args).merge(parent: Actress.current), &block).reference
  else
    ROOT.ask([:spawn, spawn_optionify(*args), block]).value
  end
end

.spawn!(*args, &block) ⇒ Object

as spawn but it’ll raise when Actor not initialized properly



54
55
56
57
# File 'lib/concurrent/actress.rb', line 54

def self.spawn!(*args, &block)
  warn '[EXPERIMENTAL] A full release of `Actress`, renamed `Actor`, is expected in the 0.7.0 release.'
  spawn(spawn_optionify(*args).merge(initialized: ivar = IVar.new), &block).tap { ivar.no_error! }
end

.spawn_optionify(actress_class, name, *args) ⇒ Object .spawn_optionify(opts) ⇒ Object

Overloads:

  • .spawn_optionify(actress_class, name, *args) ⇒ Object

    Parameters:

    • actress_class (Context)

      to be spawned

    • name (String, Symbol)

      of the instance, it’s used to generate the path of the actor

    • args

      for actress_class instantiation

  • .spawn_optionify(opts) ⇒ Object


65
66
67
68
69
70
71
72
73
# File 'lib/concurrent/actress.rb', line 65

def self.spawn_optionify(*args)
  if args.size == 1 && args.first.is_a?(Hash)
    args.first
  else
    { class: args[0],
      name:  args[1],
      args:  args[2..-1] }
  end
end