Skip to content

Commit

Permalink
fix: unified GlobalContext receiver name
Browse files Browse the repository at this point in the history
  • Loading branch information
FMotalleb committed Jul 6, 2024
1 parent a2fcd27 commit e376de6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions core/global/global_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
)

func CTX() *GlobalContext {
return ctx
return c
}

var ctx = newGlobalContext()
var c = newGlobalContext()

type (
EventListenerMap = map[string][]func()
Expand All @@ -41,15 +41,15 @@ func newGlobalContext() *GlobalContext {
return ctx
}

func (ctx *GlobalContext) EventListeners() EventListenerMap {
listeners := ctx.Value(ctxutils.EventListeners)
func (c *GlobalContext) EventListeners() EventListenerMap {
listeners := c.Value(ctxutils.EventListeners)
return listeners.(EventListenerMap)
}

func (ctx *GlobalContext) AddEventListener(event string, listener func()) {
ctx.lock.Lock()
defer ctx.lock.Unlock()
listeners := ctx.EventListeners()
func (c *GlobalContext) AddEventListener(event string, listener func()) {
c.lock.Lock()
defer c.lock.Unlock()
listeners := c.EventListeners()
listeners[event] = append(listeners[event], listener)
ctx.Context = context.WithValue(ctx.Context, ctxutils.EventListeners, listeners)
c.Context = context.WithValue(c.Context, ctxutils.EventListeners, listeners)
}

0 comments on commit e376de6

Please sign in to comment.