Skip to content

Conversation

wangzhione
Copy link

threadSafeSet[T].UnmarshalJSON Can modify threadUnsafeSet data, so need a write lock

threadSafeSet[T].UnmarshalJSON Can modify threadUnsafeSet data, so need a write lock
@wangzhione
Copy link
Author

A more appropriate approach

func (t *threadSafeSet[T]) UnmarshalJSON(b []byte) error {
	var i []T
	err := json.Unmarshal(b, &i)
	if err != nil {
		return err
	}

	t.Append(i...)
	return nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant