Coder Social home page Coder Social logo

Comments (2)

goldpasser avatar goldpasser commented on September 22, 2024

package main

import (
"fmt"

"github.com/rogeralsing/gam/actor"
"github.com/rogeralsing/goconsole"

)

type Hello struct {
Who string
}

type AreYouOK struct {
}

type ParentActor struct {
id uint64
started bool
}

func (self *ParentActor) Receive(context actor.Context) {
switch msg := context.Message().(type) {
case actor.Started:
if self.started {
context.Self().Tell(AreYouOK{})
return
}
self.started = true
fmt.Printf("parent[%v] starting\n", self.id)
props := actor.FromProducer(NewChildActor)
for i := 0; i < 100; i++ {
child := context.Spawn(props)
child.Tell(Hello{Who: "Roger"})
}
case actor.Stopped:
fmt.Printf("parent[%v] Stopped\n", self.id)
case AreYouOK:
fmt.Printf("parent[%v] recv AreYouOK\n", self.id)
default:
fmt.Printf("parent[%v] recv unknown msg, type=[%T]\n", self.id, msg)
}
}

var gParent = &ParentActor{
id: 1,
started: false}

func NewParentActor() actor.Actor {
return gParent
}

type ChildActor struct {
id uint64
}

func (self *ChildActor) Receive(context actor.Context) {
switch msg := context.Message().(type) {
case actor.Started:
fmt.Printf("child[%v] starting\n", self.id)
case actor.Stopping:
fmt.Printf("child[%v] is about shut down\n", self.id)
case actor.Stopped:
fmt.Printf("child[%v] and it's children are stopped\n", self.id)
case actor.Restarting:
fmt.Printf("child[%v] is about restart\n", self.id)
case Hello:
fmt.Printf("child[%v] recv Hello %v\n", self.id, msg.Who)
if self.id%2 == 0 {
//context.Self().Stop()
panic("panic")
}
case AreYouOK:
fmt.Println("child[%v] recv AreYouOK")
default:
fmt.Printf("child[%v] recv unknown msg, type=[%T]\n", self.id, msg)
}
}

var childId uint64 = 0

func NewChildActor() actor.Actor {
childId += 1
return &ChildActor{
id: childId}
}

func main() {
decider := func(child *actor.PID, reason interface{}) actor.Directive {
fmt.Printf("handling failure for child, reason=[%v]\n", reason)
switch reason.(type) {
default:
return actor.StopDirective
}
}
supervisor := actor.NewOneForOneStrategy(10, 1000, decider)
props := actor.
FromProducer(NewParentActor).
WithSupervisor(supervisor)
actor.Spawn(props)
console.ReadLine()
}

I modify the supervison example, but it always crash. Am I do something wrong?

from protoactor-go.

rogeralsing avatar rogeralsing commented on September 22, 2024

This has been implemented

from protoactor-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.