Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looks like code repetiton #3820

Open
janus opened this issue Oct 5, 2024 · 0 comments
Open

Looks like code repetiton #3820

janus opened this issue Oct 5, 2024 · 0 comments

Comments

@janus
Copy link

janus commented Oct 5, 2024

I noticed a pattern that's a bit hard to understand:

cm.channelsMutex.Lock()
	channel, exists = cm.channels[name]
	cm.channelsMutex.Unlock()

	if !exists {
		// Ensure we update our cache of known channels
		cm.channelsMutex.Lock()
		defer cm.channelsMutex.Unlock()

		channel, exists = cm.channels[name]
		if exists {
			return channel, nil
		}

		channel, err = cm.newChannel(name)
		if err != nil {
			return nil, err
		}

		cm.channels[name] = channel
	}```
What is the work of the second `cm.channels[name]` if the first  has exists false?
NB: getChannel function inside channel_manager.go file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant