Comments (2)
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.
This has been implemented
from protoactor-go.
Related Issues (20)
- ensureTopicKindRegistered is not a good idea HOT 1
- subscriber may block PubSubMemberDeliveryActor
- Remove sprintf logging HOT 1
- Batch message sent twice? HOT 2
- Logging is a breaking change HOT 1
- MemberStrategy is not work!!!
- Go coroutine thread safe HOT 2
- Is every actor message Receiver run in they own goroutine ? HOT 1
- How can a member within a cluster be restarted? HOT 2
- How can I make ‘Spawn’ return the error that occurred when 'Started' is received? HOT 4
- Data Race
- Possible memory leak HOT 5
- Error when sending large message to remote actors HOT 1
- Context propagation
- The release tag "0.4.0" does not work
- Protoactor underperforms in certain benchmarks
- protoc-gen-gograinv2 cannot recognize google.protobuf.Empty
- How to do grain reentrance HOT 2
- Improve code generation HOT 1
- Remove GrainResponse HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protoactor-go.