Module: Concurrent::ErlangActor::Functions

Included in:
Concurrent::ErlangActor
Defined in:
lib-edge/concurrent/edge/erlang_actor.rb

Overview

A module containing entry functions to actors like spawn_actor, terminate_actor. It can be included in environments working with actors.

Examples:

include Concurrent::ErlangActors::Functions
actor = spawn_actor :on_pool do
  receive { |data| process data }
end

See Also:

Instance Method Summary collapse

Instance Method Details

#default_actor_executorExecutorService

Returns the default executor service for actors

Returns:

  • (ExecutorService)

    the default executor service for actors



519
520
521
# File 'lib-edge/concurrent/edge/erlang_actor.rb', line 519

def default_actor_executor
  default_executor
end

#default_executorExecutorService

Returns the default executor service, may be shared by other abstractions

Returns:

  • (ExecutorService)

    the default executor service, may be shared by other abstractions



525
526
527
# File 'lib-edge/concurrent/edge/erlang_actor.rb', line 525

def default_executor
  :io
end

#spawn_actor(*args, type:, channel: Promises::Channel.new, environment: Environment, name: nil, executor: default_actor_executor, &body) ⇒ Pid

Creates an actor. Same as Environment#spawn but lacks link and monitor options.

Parameters:

  • args (Object)
  • type (:on_thread, :on_pool)
  • channel (Channel)
  • environment (Environment, Module)
  • name (#to_s)

    of the actor

  • executor (ExecutorService)

    of the actor

Returns:

See Also:



492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib-edge/concurrent/edge/erlang_actor.rb', line 492

def spawn_actor(*args,
                type:,
                channel: Promises::Channel.new,
                environment: Environment,
                name: nil,
                executor: default_actor_executor,
                &body)

  actor = ErlangActor.create type, channel, environment, name, executor
  actor.run(*args, &body)
  return actor.pid
end

#terminate_actor(pid, reason) ⇒ true

Same as Environment#terminate, but it requires pid.

Parameters:

  • pid (Pid)
  • reason (Object, :normal, :kill)

Returns:

  • (true)


509
510
511
512
513
514
515
516
# File 'lib-edge/concurrent/edge/erlang_actor.rb', line 509

def terminate_actor(pid, reason)
  if reason == :kill
    pid.tell Kill.new(nil)
  else
    pid.tell Terminate.new(nil, reason, false)
  end
  true
end