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

Polling idx没有自增 #11

Open
xuyang404 opened this issue Aug 31, 2021 · 2 comments
Open

Polling idx没有自增 #11

xuyang404 opened this issue Aug 31, 2021 · 2 comments

Comments

@xuyang404
Copy link

大佬,Polling的作用是轮询Service,但是里面的idx却并没有自增,起不到轮询的效果吧?

@xuyang404
Copy link
Author

func (p *Polling) GetService() (*discovery.Server, error) {
	if p.idx >= len(p.ser)-1 {
		p.idx = 0
	}

	if len(p.ser) == 0 {
		return nil, errors.New("404 Discovery")
	}
	return p.ser[p.idx], nil
}

是不是还确立一句p.idx += 1?并且要上锁?

@dollarkillerx
Copy link
Owner

对是有问题的, 修改idx 不推荐加锁 推荐使用原子操作 谢谢您的回复

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

2 participants