user_agent icon indicating copy to clipboard operation
user_agent copied to clipboard

Concurrency support?

Open TheHackerDev opened this issue 4 years ago • 0 comments

Does this support concurrent calls? It doesn't look like it, given that New() returns a pointer without a mutex to protect concurrent reads or writes.

This is important in the case of memory use on a web server, for example. I would rather initialize it once and call it repeatedly as opposed to re-initializing it on every client connection, which would end up needlessly adding and removing from the heap as well as increase the amount the garbage collector has to work.

Adding concurrency would simply be a matter of adding a sync.RWMutex field to the UserAgent struct, and calling the UserAgent.RWMutex field's RLock()/RUnlock() or Lock()/Unlock() methods in every library method that reads or writes to the struct, respectively.

TheHackerDev avatar Jul 10 '19 19:07 TheHackerDev