mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
Fix indentation of goroutines on loop iterator variables example code
parent
172c33a975
commit
46f073bcc1
@ -125,18 +125,18 @@ for _, val := range values {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *val) MyMethod() {
|
func (v *val) MyMethod() {
|
||||||
fmt.Println(v)
|
fmt.Println(v)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
The above example also will print last element of values, the reason is same as closure. To fix the issue declare another variable inside the loop.
|
The above example also will print last element of values, the reason is same as closure. To fix the issue declare another variable inside the loop.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
for _, val := range values {
|
for _, val := range values {
|
||||||
newVal := val
|
newVal := val
|
||||||
go newVal.MyMethod()
|
go newVal.MyMethod()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *val) MyMethod() {
|
func (v *val) MyMethod() {
|
||||||
fmt.Println(v)
|
fmt.Println(v)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user