Gerrit Bot has uploaded this change for review.
singleflight: Add lazy map init to Forget
Forget is missing lazy map initialization. If Forget is called before
any other method it will panic.
Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
GitHub-Last-Rev: 118db8f47bf75498e919e074a2aed3d5ad0e6fa0
GitHub-Pull-Request: golang/sync#16
---
M singleflight/singleflight.go
M singleflight/singleflight_test.go
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/singleflight/singleflight.go b/singleflight/singleflight.go
index 690eb85..8306b8b 100644
--- a/singleflight/singleflight.go
+++ b/singleflight/singleflight.go
@@ -204,6 +204,9 @@
// an earlier call to complete.
func (g *Group) Forget(key string) {
g.mu.Lock()
+ if g.m == nil {
+ g.m = make(map[string]*call)
+ }
if c, ok := g.m[key]; ok {
c.forgotten = true
}
diff --git a/singleflight/singleflight_test.go b/singleflight/singleflight_test.go
index 3e51203..6a9a4e9 100644
--- a/singleflight/singleflight_test.go
+++ b/singleflight/singleflight_test.go
@@ -318,3 +318,8 @@
t.Errorf("Test subprocess failed, but the crash isn't caused by panicking in Do")
}
}
+
+func TestForgetEarly(t *testing.T) {
+ var g Group
+ g.Forget("key") // calling Forget before Do/DoChan should not panic
+}
To view, visit change 417894. To unsubscribe, or for help writing mail filters, visit settings.
Gerrit Bot uploaded patch set #2 to this change.
singleflight: Add lazy map init to Forget
Forget is missing lazy map initialization. If Forget is called before
any other method it will panic.
Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
GitHub-Last-Rev: 667518ffb9fb1e217af7b1ec84953f7774bc97f7
GitHub-Pull-Request: golang/sync#16
---
M singleflight/singleflight.go
M singleflight/singleflight_test.go
2 files changed, 22 insertions(+), 0 deletions(-)
To view, visit change 417894. To unsubscribe, or for help writing mail filters, visit settings.
Gerrit Bot uploaded patch set #3 to this change.
singleflight: Add lazy map init to Forget
Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
GitHub-Last-Rev: 667518ffb9fb1e217af7b1ec84953f7774bc97f7
GitHub-Pull-Request: golang/sync#16
---
M singleflight/singleflight.go
M singleflight/singleflight_test.go
2 files changed, 19 insertions(+), 0 deletions(-)
To view, visit change 417894. To unsubscribe, or for help writing mail filters, visit settings.
Gopher Robot abandoned this change.
To view, visit change 417894. To unsubscribe, or for help writing mail filters, visit settings.