Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actor pool terminated event sent as message #813

Open
kj opened this issue Jun 22, 2019 · 0 comments
Open

Actor pool terminated event sent as message #813

kj opened this issue Jun 22, 2019 · 0 comments
Assignees
Labels
question An user question, does not change the library.

Comments

@kj
Copy link

kj commented Jun 22, 2019

  • Operating system: Linux
  • Ruby implementation: Ruby
  • concurrent-ruby version: 1.1.5
  • concurrent-ruby-edge version: 0.5.0

Given this code:

require 'concurrent-edge'

class WorkerActor < Concurrent::Actor::RestartingContext
  def on_event(event)
    puts "#{name} event: #{event.inspect}"
  end
end

class Actor < Concurrent::Actor::RestartingContext
  def initialize
    @worker_pool = Concurrent::Actor::Utils::Pool.spawn('worker_pool', 10) do |index|
      WorkerActor.spawn(name: "worker[#{index}]", supervise: true)
    end
  end

  def on_message(message)
    puts "#{name} message: #{message.inspect}"
  end

  def on_event(event)
    puts "#{name} event: #{event.inspect}"
  end
end

actor = Actor.spawn(name: 'parent')

actor << :terminate!

sleep 0.1

-why does the Actor receive both an event :terminated and a message :terminated? Output from the above:

parent event: [:terminated, nil]
worker[0] event: [:terminated, nil]
worker[1] event: [:terminated, nil]
worker[2] event: [:terminated, nil]
worker[3] event: [:terminated, nil]
worker[4] event: [:terminated, nil]
worker[5] event: [:terminated, nil]
worker[6] event: [:terminated, nil]
worker[7] event: [:terminated, nil]
worker[8] event: [:terminated, nil]
worker[9] event: [:terminated, nil]
parent message: [:terminated, nil]

It only seems to receive a message when I use a Pool. If I replace the #initialize method with:

@worker = WorkerActor.spawn(name: 'worker', supervise: true)

Then the output includes only events and no message:

parent event: [:terminated, nil]
worker event: [:terminated, nil]
@pitr-ch pitr-ch added the question An user question, does not change the library. label Aug 24, 2019
@pitr-ch pitr-ch self-assigned this Aug 24, 2019
@pitr-ch pitr-ch added this to Nope in Hackathon Aug 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question An user question, does not change the library.
Development

No branches or pull requests

2 participants