Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/overvenus/actor
https://github.com/overvenus/actor
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/overvenus/actor
- Owner: overvenus
- License: apache-2.0
- Created: 2023-01-11T09:16:47.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-13T22:04:59.000Z (10 months ago)
- Last Synced: 2024-10-14T06:06:39.182Z (3 months ago)
- Language: Go
- Size: 107 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# actor - A Minimum Go Actor Framework
[![GoDoc](https://godoc.org/github.com/overvenus/actor?status.svg)](https://pkg.go.dev/github.com/overvenus/actor?tab=doc)
## Features
* A minimum actor runtime.
* Run 100k+ actors concurrently in a pool of goroutine (8*GOMAXPROCS).
* Comprehensive metrics monitoring.## Status
This package is kind of *stable*, it's currently used by [TiFlow](https://github.com/pingcap/tiflow) project in production.
New features or bug fixes are welcome!
## Examples
### Ping pong
```go
type pingpong struct {
peer actor.ID
router *actor.Router[int]
}func (p *pingpong) Poll(ctx context.Context, msgs []message.Message[int]) bool {
select {
case <-ctx.Done():
return false
default:
}
println("recv from peer", p.peer, msgs[0].Value)
p.router.Send(p.peer, msgs[0])
return true
}func (p *pingpong) OnClose() {}
func main() {
sys, router := actor.NewSystemBuilder[int]("ping-pong").Build()
ctx := context.Background()
sys.Start(ctx)a1 := &pingpong{peer: actor.ID(2), router: router}
mb1 := actor.NewMailbox[int](actor.ID(1), 1)
sys.Spawn(mb1, a1)a2 := &pingpong{peer: actor.ID(1), router: router}
mb2 := actor.NewMailbox[int](actor.ID(2), 2)
sys.Spawn(mb2, a2)// Initiate ping pong.
router.Send(actor.ID(1), message.ValueMessage(0))time.Sleep(3 * time.Second)
sys.Stop()
}
```