Skip to content

Commit

Permalink
Adding methods to add subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
murphysean committed Mar 31, 2018
1 parent dc51c0a commit 0f86b78
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions game.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewSecretHitler() *SecretHitler {
type SecretHitler struct {
Game

log *os.File
Log *os.File
m sync.RWMutex

//Make the engine a subscriber
Expand All @@ -91,8 +91,8 @@ func (sh *SecretHitler) SubmitEvent(ctx context.Context, e Event) error {
}
sh.Game = g
//Persist the event to a file
if sh.log != nil {
enc := json.NewEncoder(sh.log)
if sh.Log != nil {
enc := json.NewEncoder(sh.Log)
err := enc.Encode(ne)
if err != nil {
return err
Expand All @@ -104,6 +104,18 @@ func (sh *SecretHitler) SubmitEvent(ctx context.Context, e Event) error {
return nil
}

func (sh *SecretHitler) AddSubscriber(key string, channel chan<- Event) {
sh.m.Lock()
sh.subscribers[key] = channel
sh.m.Unlock()
}

func (sh *SecretHitler) RemoveSubscriber(key string) {
sh.m.Lock()
delete(sh.subscribers, key)
sh.m.Unlock()
}

func (sh *SecretHitler) BroadcastEvent(e Event) {
sh.m.RLock()
defer sh.m.RUnlock()
Expand Down

0 comments on commit 0f86b78

Please sign in to comment.