代码拉取完成,页面将自动刷新
package utils
import (
"sync"
)
type SyncList struct {
lock *sync.RWMutex
list []interface{}
}
func (this *SyncList) Add(obj interface{}) {
this.lock.Lock()
this.list = append(this.list, obj)
this.lock.Unlock()
}
func (this *SyncList) Get(index int) (n interface{}) {
this.lock.RLock()
n = this.list[index]
this.lock.RUnlock()
return
}
func (this *SyncList) Remove(index int) (ok bool) {
this.lock.Lock()
if len(this.list) < index+1 {
ok = false
this.lock.Unlock()
return
}
temp := this.list[:index]
this.list = append(temp, this.list[index+1:]...)
ok = true
this.lock.Unlock()
return
}
func (this *SyncList) GetAll() []interface{} {
this.lock.RLock()
l := make([]interface{}, len(this.list))
copy(l, this.list)
this.lock.RUnlock()
return l
}
//func (this *SyncList) Range(fn func(i int, v interface{}) bool) {
// this.lock.Lock()
// for i, one := range this.list {
// if !fn(i, one) {
// break
// }
// }
// this.lock.Unlock()
//}
//func (this *SyncList) Find() {
// for _,one := range this.list{
// if
// }
//}
func NewSyncList() *SyncList {
return &SyncList{
lock: new(sync.RWMutex),
list: make([]interface{}, 0),
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。