https://github.com/tideland/go-actor
Go package supporting easier synchronous and asynchronous concurrent programming based on the actor model.
https://github.com/tideland/go-actor
actor-model concurrency go golang
Last synced: 6 months ago
JSON representation
Go package supporting easier synchronous and asynchronous concurrent programming based on the actor model.
- Host: GitHub
- URL: https://github.com/tideland/go-actor
- Owner: tideland
- License: bsd-3-clause
- Created: 2021-09-02T14:10:50.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-06-11T14:04:31.000Z (over 2 years ago)
- Last Synced: 2025-03-25T09:49:47.824Z (7 months ago)
- Topics: actor-model, concurrency, go, golang
- Language: Go
- Homepage:
- Size: 35.2 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Tideland Go Actor
[](https://github.com/tideland/go-actor)
[](https://raw.githubusercontent.com/tideland/go-actor/master/LICENSE)
[](https://github.com/tideland/go-actor/blob/master/go.mod)
[](https://pkg.go.dev/mod/tideland.dev/go/actor?tab=packages)

[](https://goreportcard.com/report/tideland.dev/go/actor)### Description
**Tideland Go Actor** provides running backend goroutines for the sequential execution
of anonymous functions following the actor model. The Actors can work asynchronously as
well as synchronously. Additionally the Actor provides methods for the repeated execution
of Actions. So background operation can be automated.The options for the constructor allow to pass a context for the Actor, the capacity
of the Action queue, a recoverer function in case of an Action panic and a finalizer
function when the Actor stops.All together simplifies the implementation of concurrent code.
I hope you like it. ;)
### Example
```go
type Counter struct {
counter int
act *actor.Actor
}func NewCounter() (*Counter, error) {
act, err := actor.Go()
if err != nil {
return nil, err
}
c := &Counter{
counter: 0,
act: act,
}
// Increment the counter every second.
interval := 1 * time.Second
c.act.Repeat(interval, func() {
c.counter++
})
return c, nil
}func (c *Counter) Incr() error {
return c.act.DoAsync(func() {
c.counter++
})
}func (c *Counter) Get() (int, error) {
var counter int
if err := c.act.DoSync(func() {
counter = c.counter
}); err != nil {
return 0, err
}
return counter, nil
}func (c *Counter) Stop() {
c.act.Stop()
}
```### Contributors
- Frank Mueller (https://github.com/themue / https://github.com/tideland / https://tideland.dev)