github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/prepare/23_proto_actor/remoterouting/client/local.go (about)

     1  package main
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/AsynkronIT/protoactor-go/actor"
     7  	"github.com/AsynkronIT/protoactor-go/examples/remoterouting/messages"
     8  
     9  	"log"
    10  )
    11  
    12  type localActor struct {
    13  	count        int
    14  	wgStop       *sync.WaitGroup
    15  	messageCount int
    16  }
    17  
    18  func (state *localActor) Receive(context actor.Context) {
    19  	switch context.Message().(type) {
    20  	case *messages.Pong:
    21  		state.count++
    22  		if state.count%50000 == 0 {
    23  			log.Println(state.count)
    24  		}
    25  		if state.count == state.messageCount {
    26  			log.Println("Done")
    27  			state.wgStop.Done()
    28  		}
    29  	}
    30  }
    31  
    32  func newLocalActor(stop *sync.WaitGroup, messageCount int) actor.Producer {
    33  	stop.Add(1)
    34  	return func() actor.Actor {
    35  		return &localActor{
    36  			wgStop:       stop,
    37  			messageCount: messageCount,
    38  		}
    39  	}
    40  }