type Tasks map[int]CustomValue
func (t *Tasks) Put(task MyTask) {
(*t)[len(*t)] = task
return len(*t) - 1
}
func (t *Tasks) Get(taskID int) interface{} {
defer func() { // Is this OK???
delete(*t, taskID)
}()
return (*t)[jobID].GetValue()
}
Here is my code of Go. Basically, I'm using a map to store some "key-value"s. And I have two functions Put
and Get
.
After getting the value, I want to delete the element from the map.
Can I simply use the defer mechanism to do so? I don't know if the defer function must be invoked after return.