Skip to content

Commit

Permalink
add missed lock for Count
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Jul 8, 2020
1 parent 7d32720 commit 1965fb4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestNew(t *testing.T) {

ob := goob.New()
s := ob.Subscribe(ctx)
size := 10000
size := 1000

expected := []int{}
go func() {
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestMultipleConsumers(t *testing.T) {
s1 := ob.Subscribe(ctx)
s2 := ob.Subscribe(ctx)
s3 := ob.Subscribe(ctx)
size := 10000
size := 1000

expected := []int{}
go func() {
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestFilter(t *testing.T) {
func TestMonkey(t *testing.T) {
wg := sync.WaitGroup{}
count := int32(0)
roundSize := 10000
roundSize := 1000
size := 100

run := func() {
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func (ob *Observable) Publish(e Event) {

// Count of the subscribers
func (ob *Observable) Count() int {
ob.lock.Lock()
defer ob.lock.Unlock()
return len(ob.subscribers)
}

Expand Down

0 comments on commit 1965fb4

Please sign in to comment.