本文整理匯總了Golang中github.com/rogeralsing/gam/actor.Context類的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Context類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Receive
func (state *BecomeActor) Receive(context actor.Context) {
switch msg := context.Message().(type) {
case Hello:
fmt.Printf("Hello %v\n", msg.Who)
context.Become(state.Other)
}
}
示例2: sendEnvelopes
func (state *endpointWriter) sendEnvelopes(msg []interface{}, ctx actor.Context) {
envelopes := make([]*messages.MessageEnvelope, len(msg))
for i, tmp := range msg {
envelopes[i] = tmp.(*messages.MessageEnvelope)
}
batch := &messages.MessageBatch{
Envelopes: envelopes,
}
err := state.stream.Send(batch)
if err != nil {
ctx.Stash()
log.Println("Failed to send to host", state.host)
panic("restart")
}
}
示例3: Receive
func (*remoteActor) Receive(context actor.Context) {
switch msg := context.Message().(type) {
case *messages.StartRemote:
log.Println("Starting")
msg.Sender.Tell(&messages.Start{})
case *messages.Ping:
msg.Sender.Tell(&messages.Pong{})
}
}
示例4: Receive
func (state *endpointWriter) Receive(ctx actor.Context) {
switch msg := ctx.Message().(type) {
case actor.Started:
state.initialize()
case actor.Stopped:
state.conn.Close()
case actor.Restarting:
state.conn.Close()
case []interface{}:
state.sendEnvelopes(msg, ctx)
default:
log.Fatal("Unknown message", msg)
}
}
示例5: Receive
func (state *endpointManager) Receive(ctx actor.Context) {
switch msg := ctx.Message().(type) {
case actor.Started:
state.connections = make(map[string]*actor.PID)
log.Println("Started EndpointManager")
case *messages.MessageEnvelope:
pid, ok := state.connections[msg.Target.Host]
if !ok {
props := actor.
FromProducer(newEndpointWriter(msg.Target.Host, state.config)).
WithMailbox(newEndpointWriterMailbox(state.config.batchSize, 1000000))
pid = actor.Spawn(props)
state.connections[msg.Target.Host] = pid
}
pid.Tell(msg)
}
}
示例6: Other
func (state *BecomeActor) Other(context actor.Context) {
switch msg := context.Message().(type) {
case Hello:
fmt.Printf("%v, ey we are now handling messages in another behavior", msg.Who)
}
}