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

sync: Add a method to WaitGroup to simplify Add, Done, go func() #44473

Closed
darkfeline opened this issue Feb 21, 2021 · 1 comment
Closed

sync: Add a method to WaitGroup to simplify Add, Done, go func() #44473

darkfeline opened this issue Feb 21, 2021 · 1 comment

Comments

@darkfeline
Copy link
Contributor

When using sync.WaitGroup, very often it is used like so:

var wg sync.WaitGroup
wg.Add(1)
go func() {
    defer wg.Done()
    // Some code
}()

Of course, this is not the only use case, but it is by far the most common. It would be convenient to add a method used like:

var wg sync.WaitGroup
wg.Run(func() {
    // Some code
})
func (wg *sync.WaitGroup) Run(f func()) {
    wg.Add(1)
    go func() {
        defer wg.Done()
        f()
    }()
}
@seankhliao
Copy link
Member

Duplicate of #39863

@seankhliao seankhliao marked this as a duplicate of #39863 Feb 21, 2021
@golang golang locked and limited conversation to collaborators Feb 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants