Remove package variables for tracking handlers#5
Conversation
Previously various handlers were stored in maps with IDs, but because there was no synchronization, it meant that some functions were not safe for concurrent use. Rather than add synchronization, I've removed the maps and used pointers instead of IDs. This is concurrency-safe and cheaper since no map lookups are required.
|
Hi, the problem is that after the GC is executed the pointers doesn't work anymore (run the tests and you will see). I tried many things in the past (also your solution) but this was the only way to solve it. You can read this post where I have described my problem: https://groups.google.com/forum/#!topic/golang-nuts/24BCnAWcqrw |
|
Hmmm, I ran the tests locally and didn't have any problems. I guess I got lucky. The issue makes sense though. Here's an alternative proposal, then (talking about comparators, but similar things would happen to merge operators and slice transforms):
This keeps the interfaces alive and safe from being collected as long as the |
|
I tried your proposal but the funny thing is that hold a ref to the handler did not help. I tried after this to save the pointer and lo and behold, it worked! You ok with my implementation?53c433f |
|
Yeah, you'd have to save a pointer to the interface instead of just a copy of the interface, since you need to make sure the interface value itself also survives. I do like the idea of getting rid of the Comparator struct type and having only an interface, but it's up to you what you want to do. |
|
Ok, for now I will merge only the pointer stuff. Your idea is good, its reduce one extra step to create custom handlers and simplifies the API. |
Remove package variables (based on #5)
|
Merged by #7 |
GOR-1: Add MultiGet support
Previously various handlers were stored in maps with IDs, but because there was
no synchronization, it meant that some functions were not safe for concurrent
use.
Rather than add synchronization, I've removed the maps and used pointers
instead of IDs. This is concurrency-safe and cheaper since no
map lookups are required.