Skip to content

Commit

Permalink
docs: nano.Invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
lonng committed Sep 19, 2018
1 parent 6e7c921 commit cac7510
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ func (r *RemoteComponent) DemoHandler(s *session.Session, msg *pb.DemoMsg) error
}
```

#### How to execute the asynchronous task

```
func (manager *PlayerManager) Login(s *session.Session, msg *ReqPlayerLogin) error {
var onDBResult = func(player *Player) {
manager.players = append(manager.players, player)
s.Push("PlayerSystem.LoginSuccess", &ResPlayerLogin)
}
// run slow task in new gorontine
go func() {
player, err := db.QueryPlayer(msg.PlayerId) // ignore error in demo
// handle result in main logical gorontine
nano.Invoke(func(){ onDBResult(player) })
}
return nil
}
```

The Nano will remain simple, but you can perform any operations in the component and get the desired goals. You can startup a group of `Nano` application as agent to dispatch message to backend servers.

## Documents
Expand Down

0 comments on commit cac7510

Please sign in to comment.