Created
October 21, 2019 08:26
-
-
Save pelly-ryu/5a90a10c98e5947c84248042d6889db0 to your computer and use it in GitHub Desktop.
test for range with goroutine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestForRange(t *testing.T) { | |
m := map[string]string{ | |
"a": "1", | |
"b": "2", | |
} | |
go func() { | |
time.Sleep(1*time.Second) | |
m["b"] = "3" | |
fmt.Println("!") | |
}() | |
for k, v := range m { | |
time.Sleep(700 * time.Millisecond) | |
fmt.Println(k, v, m[k]) | |
fmt.Println(m) | |
} | |
/* Output: | |
a 1 1 | |
map[a:1 b:2] | |
! | |
b 2 3 | |
map[a:1 b:3] | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment