Skip to content

Commit

Permalink
#24 Prepare for versioned release (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
docktermj authored May 12, 2023
1 parent 1711fb4 commit 649a388
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

-

## [0.2.3] - 2023-05-12

### Added in 0.2.3

- Fix bug (nil observer)

## [0.2.2] - 2023-05-10

### Added in 0.2.2
Expand Down
18 changes: 11 additions & 7 deletions subject/subject_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ Input
*/
func (subject *SubjectImpl) RegisterObserver(ctx context.Context, observer observer.Observer) error {
var err error = nil
lock.RLock()
defer lock.RUnlock()
if !contains(ctx, subject.observerList, observer) {
subject.observerList = append(subject.observerList, observer)
if observer != nil {
lock.RLock()
defer lock.RUnlock()
if !contains(ctx, subject.observerList, observer) {
subject.observerList = append(subject.observerList, observer)
}
}
return err
}
Expand All @@ -121,8 +123,10 @@ Input
*/
func (subject *SubjectImpl) UnregisterObserver(ctx context.Context, observer observer.Observer) error {
var err error = nil
lock.RLock()
defer lock.RUnlock()
subject.observerList = removeFromSlice(ctx, subject.observerList, observer)
if observer != nil {
lock.RLock()
defer lock.RUnlock()
subject.observerList = removeFromSlice(ctx, subject.observerList, observer)
}
return err
}

0 comments on commit 649a388

Please sign in to comment.