Skip to content

Instantly share code, notes, and snippets.

@Horaddrim
Created November 2, 2017 03:09
Show Gist options
  • Select an option

  • Save Horaddrim/98da87c5b25761ebb3619e558c3e6fe4 to your computer and use it in GitHub Desktop.

Select an option

Save Horaddrim/98da87c5b25761ebb3619e558c3e6fe4 to your computer and use it in GitHub Desktop.
package main
// Actor ... Defines an actor, that have always to have a flow to "act" and a
// key to manage the "action"
type Actor struct {
isAvailable bool
flow chan int
}
func (actor *Actor) subscribe(c chan int) {
actor.flow = c
actor.isAvailable = false
}
func (actor *Actor) unsubscribe() {
actor.flow = nil
actor.isAvailable = true
}
func (actor *Actor) action() {
if actor.flow != nil {
actor.flow <- 123
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment