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

proposal: Go 2: run for loop in a goroutine with go keyword #36407

Closed
mdaliyan opened this issue Jan 6, 2020 · 4 comments
Closed

proposal: Go 2: run for loop in a goroutine with go keyword #36407

mdaliyan opened this issue Jan 6, 2020 · 4 comments
Labels
FrozenDueToAge LanguageChange Suggested changes to the Go language Proposal Proposal-FinalCommentPeriod v2 An incompatible library change
Milestone

Comments

@mdaliyan
Copy link

mdaliyan commented Jan 6, 2020

Go 2 Proposal

go keyword runs a function in a goroutine. So when you want to run a for loop in a separate goroutine, you have to do such thing:

go func() {
	for {
		// do something regularly
	}
}()

What if you could run a for loop like this ?

go for {
	// do something regularly
}

I know it's a little confusing when it comes to considering the scope but I think it looks clean and minimal.

@toothrot toothrot changed the title Run for loop in a goroutine with go keyword proposal: Go 2: run for loop in a goroutine with go keyword Jan 6, 2020
@gopherbot gopherbot added this to the Proposal milestone Jan 6, 2020
@bradfitz bradfitz added the LanguageChange Suggested changes to the Go language label Jan 6, 2020
@toothrot
Copy link
Contributor

toothrot commented Jan 6, 2020

This looks like related to #24210.

@ianlancetaylor ianlancetaylor added the v2 An incompatible library change label Jan 6, 2020
@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Jan 6, 2020

Why should we permit specifically go for and not any other kind of statement?

The current go statement simply accepts any function call. That is easy to understand. Supporting go with a for statement doesn't seem to me like a particularly common case, and I don't see why we should add a special case for it.

@ianlancetaylor
Copy link
Contributor

Based on emoji voting this proposal is not popular. Also as noted above it is not general. For these reasons, this is a likely decline. Leaving open for four weeks for final comments.

@bradfitz
Copy link
Contributor

I know it's a little confusing when it comes to considering the scope but I think it looks clean and minimal.

The problem with both this proposal and the normal way of writing it (go func() { for { ... ) is that the stacktraces are ugly when you're debugging a server. It's nicer to give those permanent goroutines names.

@golang golang locked and limited conversation to collaborators Jan 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge LanguageChange Suggested changes to the Go language Proposal Proposal-FinalCommentPeriod v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

5 participants