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

Describe the supervisor/worker pattern #30

Open
mfelsche opened this issue Nov 3, 2017 · 0 comments
Open

Describe the supervisor/worker pattern #30

mfelsche opened this issue Nov 3, 2017 · 0 comments

Comments

@mfelsche
Copy link

mfelsche commented Nov 3, 2017

It has been raised as a question several times and is worth explaining as a pony pattern.
An example from @SeanTAllen is here:

actor Main
  new create(env: Env) =>
    Supervisor(env.out).run()

actor Worker
  let _supervisor: Supervisor
  
  new create(supervisor: Supervisor) =>
    _supervisor = supervisor
    
  be work() =>
    // do some stuff
    _supervisor.done(this)

actor Supervisor
  let _out: StdStream
  let _worker: Worker
  
  new create(out: StdStream) =>
    _out = out
    _worker = Worker(this)
    
  be run() =>
    _worker.work()
    
  be done(worker: Worker) =>
    if (worker is _worker) then
      _out.print("My worker finished\n")
    else
      _out.print("Odd, a worker that isn't mine told me it was done. Weird\n")
    end

https://playground.ponylang.org/?gist=1b8684fef6a856fcebbf3528f05214cd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant