func (rep *Representative) Claim(instance instance.Instance) { rep.lock.Lock() defer rep.lock.Unlock() _, ok := rep.instances[instance.InstanceGuid] if !ok { panic("wat?") } instance.Tentative = false rep.instances[instance.InstanceGuid] = instance }
func (rep *Representative) ReserveAndRecastVote(instance instance.Instance) (float64, error) { rep.lock.Lock() defer rep.lock.Unlock() if !rep.hasRoomFor(instance) { return 0, InsufficientResources } score := rep.score(instance) //recompute score *first* instance.Tentative = true rep.instances[instance.InstanceGuid] = instance //*then* make reservation return score, nil }