MCPcopy Create free account
hub / github.com/astercloud/aster / runBasicDemo

Function runBasicDemo

examples/actor/main.go:229–257  ·  view source on GitHub ↗

============================================================================= 演示命令 ============================================================================= runBasicDemo 基础 Ping-Pong 演示

(ctx context.Context, cmd *cli.Command)

Source from the content-addressed store, hash-verified

227
228// runBasicDemo 基础 Ping-Pong 演示
229func runBasicDemo(ctx context.Context, cmd *cli.Command) error {
230 fmt.Println("\n🎯 基础 Actor 演示(Ping-Pong)")
231 fmt.Println(strings.Repeat("=", 50))
232
233 // 创建 Actor 系统
234 system := actor.NewSystem("basic-demo")
235 defer system.Shutdown()
236
237 // 创建 Echo Actor
238 echo := &EchoActor{name: "Echo"}
239 pid := system.Spawn(echo, "echo")
240
241 fmt.Println("\n📤 发送 3 个 Ping 消息...")
242
243 // 发送多个 Ping 并等待 Pong
244 for i := 1; i <= 3; i++ {
245 resp, err := pid.Request(&PingMsg{Count: i}, 5*time.Second)
246 if err != nil {
247 return fmt.Errorf("请求失败: %w", err)
248 }
249
250 if pong, ok := resp.(*PongMsg); ok {
251 fmt.Printf("📥 收到 Pong(%d)\n", pong.Count)
252 }
253 }
254
255 fmt.Println("\n✅ 基础演示完成!")
256 return nil
257}
258
259// runCounterDemo 并发计数器演示
260func runCounterDemo(ctx context.Context, cmd *cli.Command) error {

Callers

nothing calls this directly

Calls 5

ShutdownMethod · 0.95
SpawnMethod · 0.95
NewSystemFunction · 0.92
PrintfMethod · 0.80
RequestMethod · 0.45

Tested by

no test coverage detected