You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When putting an item back to the pool the fields are left with the any values it has at this point.
The next caller to the Get will get this dirty object.
My proposal is to create a Reset function field, much like the New one, which takes as an argument the object in question. This reset function should be called right before the item is put back to the internal store.
The text was updated successfully, but these errors were encountered:
josharian
changed the title
proposal sync.Pool: Reset item before putting it back to the pool
proposal: add Reset field to sync.Pool to reset item before putting it back to the pool
Jan 12, 2017
The Reset function will have to accept an interface{}, which means that you'll have to type assert inside it, at which point I suspect most people will choose to simply reset inline, or have a typed helper func that calls Put, as @mvdan suggested.
sync.Pool is a low-level interface. It's a feature that you can get a "dirty" (read: initialized) item out of the pool again. If you need to zero some things, you can do so before Put or after Get.
When putting an item back to the pool the fields are left with the any values it has at this point.
The next caller to the Get will get this dirty object.
My proposal is to create a Reset function field, much like the New one, which takes as an argument the object in question. This reset function should be called right before the item is put back to the internal store.
The text was updated successfully, but these errors were encountered: