Skip to content

Instantly share code, notes, and snippets.

@pelly-ryu
Created October 21, 2019 08:26
Show Gist options
  • Save pelly-ryu/5a90a10c98e5947c84248042d6889db0 to your computer and use it in GitHub Desktop.
Save pelly-ryu/5a90a10c98e5947c84248042d6889db0 to your computer and use it in GitHub Desktop.
test for range with goroutine
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