Created
November 2, 2017 03:09
-
-
Save Horaddrim/98da87c5b25761ebb3619e558c3e6fe4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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