Examples from a medium post 1
package main
import (
"fmt"
)
func main() {
actor := NewActor()
go actor.Receive()
actor.Send("Hello, world!")
actor.Send("This is a message.")
// time.Sleep(time.Second)
fmt.Println("vim-go")
}
type Actor struct {
inbox chan string
}
func NewActor() *Actor {
return &Actor{
inbox: make(chan string),
}
}
func (a *Actor) Receive() {
for msg := range a.inbox {
fmt.Println(msg)
}
}
func (a *Actor) Send(msg string) {
a.inbox <- msg
}