Skip to content

Commit

Permalink
Add Clone to Event
Browse files Browse the repository at this point in the history
  • Loading branch information
lukazakrajsek-soniox committed Oct 3, 2024
1 parent ddf9800 commit f39d31f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package events
import (
"fmt"
"log/slog"
"maps"
"sync"

"github.com/google/uuid"
Expand Down Expand Up @@ -45,6 +46,17 @@ func NewEvent(logger *slog.Logger) *Event {
return e
}

func (e *Event) Clone() *Event {
e.mutex.RLock()
attrs := maps.Clone(e.attrs)
e.mutex.RUnlock()

return &Event{
attrs: attrs,
baseLogger: e.baseLogger,
}
}

func (e *Event) SetAttr(key string, value any) {
e.mutex.Lock()
e.attrs[key] = slog.AnyValue(value)
Expand Down

0 comments on commit f39d31f

Please sign in to comment.