Go语言interface的value.(type)使用小技巧
来源:互联网 发布:js input 样式 编辑:程序博客网 时间:2024/05/19 13:10
<pre name="code" class="plain">package mainimport ("container/list""fmt""math/rand""sync""time")type INFO struct {lock sync.MutexName stringTime int64}var List *list.List = list.New()func main() {var Info INFOgo func() {for i := 0; i < 5; i++ {time.Sleep(time.Duration(1e9 * int64(rand.Intn(5))))Info.lock.Lock()Info.Name = fmt.Sprint("Name", i)Info.Time = time.Now().Unix() + 3Info.lock.Unlock()List.PushBack(Info)}}()go Getgoods()select {}}func Getgoods() {for {time.Sleep(1e8)for List.Len() > 0 {N, T := List.Remove(List.Front()).(INFO).name()now := time.Now().Unix()if T-now <= 0 {fmt.Println(N, T, now)continue}time.Sleep(time.Duration((T - now) * 1e9))fmt.Println(N, T, now)}}}func (i INFO) name() (string, int64) {return i.Name, i.Time}
0 0
- Go语言interface的value.(type)使用小技巧
- go语言type使用小技巧
- Go语言中cannot convert adminname (type interface {}) to type *: need type assertion的解决办法
- go语言中的interface使用
- GO interface的使用
- 浅解 go 语言的 interface
- go interface type
- go语言中type的几种使用
- go语言中type的几种使用
- 测试Go语言的interface的效率
- go语言 interface 初探
- Go语言interface详解
- Go语言基础:Interface
- Go语言interface详解
- Go语言interface详解
- Go语言-interface
- GO语言interface
- Go语言-interface
- android service是否在同一个内存的问题
- 运行时的程序保存core文件
- android.app.FragmentManager 与 android.support.v4.app.FragmentManager带来的若干Error
- 不需要数据线手机连电脑进行调试的方法(特别好用)
- ORA-28000: the account is locked-的解决办法
- Go语言interface的value.(type)使用小技巧
- android 开源组件
- 辨析nyoj42和hdu1116(欧拉图有向与无向区分)
- RT-Thread内核之线程调度(一)
- MATLAB学习笔记(十二)
- Android中Parcelable接口用法
- Java JSON Date类型数据处理相关问题
- C++ 容器类
- ant android打包时获取版本号