Skip to content

Commit

Permalink
jerk
Browse files Browse the repository at this point in the history
  • Loading branch information
therealpaulgg committed Feb 21, 2024
1 parent ab6e7c4 commit a8bf354
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/web/live/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,18 @@ type SafeChallengeResponseDict struct {
dict map[string]Something
}

// Now, whenever you access ChallengeResponseDict, use the mutex to synchronize access.
// For example, when writing to the map:
// Utility method for safely writing to the dict
func (c *SafeChallengeResponseDict) WriteChallenge(challengePhrase string, data Something) {
c.mux.Lock() // lock before accessing the map
c.mux.Lock()
c.dict[challengePhrase] = data
c.mux.Unlock() // unlock after accessing the map
c.mux.Unlock()
}

// And when reading or deleting from the map:
// Utility method for safely reading from the dict
func (c *SafeChallengeResponseDict) ReadChallenge(challengePhrase string) (Something, bool) {
c.mux.Lock() // lock before accessing the map
c.mux.Lock()
data, exists := c.dict[challengePhrase]
c.mux.Unlock() // unlock after accessing the map
c.mux.Unlock()
return data, exists
}

Expand Down

0 comments on commit a8bf354

Please sign in to comment.