Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/waterlink/goactor
Thin Actor implementation in Golang
https://github.com/waterlink/goactor
Last synced: 30 days ago
JSON representation
Thin Actor implementation in Golang
- Host: GitHub
- URL: https://github.com/waterlink/goactor
- Owner: waterlink
- License: mit
- Created: 2015-03-07T18:12:01.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-08T01:58:22.000Z (almost 10 years ago)
- Last Synced: 2024-10-16T07:16:08.256Z (3 months ago)
- Language: Go
- Size: 227 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# goactor
Thin Actor implementation in golang.
## Installation
Specify it as a dependency:
```go
import "github.com/waterlink/goactor"
```And run
```bash
go get
```## Usage
Simple example
```go
type Relationships struct {
goactor.Actor
}func (this *Relationships) Act(message goactor.Any) {
event, ok := message.(Event)
if !ok {
return # ignore or handle it
}# ... handle event ...
}
```To run this actor:
```go
relationships := Relationships{goactor.NewActor()}
goactor.Go(&relationships, "Relationships Task")
```To send anything to its inbox, one can use:
```go
# Async send
relationships.Send(anEvent)# Sync send, will block, until actor consumes
relationships.SyncSend(anEvent)
```Actor needs following methods to be implemented:
- `(*goactor.Actor) Act(message goactor.Any)` - one lifecylce: get inbox message and do something important
If you want to kill an actor, then use `Die()` method on it:
```go
# usage from outside of an actor
relationships.Die()# usage from inside of an actor
this.Die()
```Note: it will still finish current lifecycle and will die on beginning of the next one.
Look at the full [example](examples/example.go)
For further details you can look at the test: [goactor_test.go](goactor_test.go)
## Contributing
1. Fork it ( https://github.com/waterlink/goactor/fork )
2. Create a branch ( `git checkout -b a-feature` )
3. Commit your changes ( `git commit -am "A feature"` )
4. Push to the branch ( `git push -u origin a-feature` )
5. Create a new Pull Request