代码拉取完成,页面将自动刷新
package coroutine
import (
"fmt"
"gitee.com/quant1x/gox/concurrent"
"gitee.com/quant1x/gox/timestamp"
"strconv"
"testing"
"time"
)
var (
rollingOnce RollingOnce
cache1 = concurrent.NewHashMap[string, int]()
)
func lazyCacheInit() {
for i := 0; i < 5; i++ {
k := strconv.Itoa(i)
//cache[k] = i
cache1.Set(k, i)
fmt.Println("reset", k, "=>", i)
}
}
func cacheGetInt(key string) (int, bool) {
rollingOnce.Do(lazyCacheInit)
v, ok := cache1.Get(key)
return v, ok
}
func cacheSetInt(key string, value int) {
rollingOnce.Do(lazyCacheInit)
cache1.Set(key, value)
}
func TestRollingOnce(t *testing.T) {
var o1 RollingOnce
o1.Do(func() {
})
o1.Close()
rwCount := 1000
producer := func() {
for i := 0; i < rwCount; i++ {
k := strconv.Itoa(i % 5)
cacheSetInt(k, i)
fmt.Println(k, "=>", i)
time.Sleep(time.Millisecond * 10)
}
}
reader := func() {
for i := 0; i < rwCount; i++ {
k := strconv.Itoa(i % 5)
v, ok := cacheGetInt(k)
fmt.Println(v, "<=", i, ":", ok)
_ = v
_ = ok
time.Sleep(time.Millisecond * 10)
}
}
go producer()
go reader()
count := 60
for i := 0; i < count; i++ {
//once.Reset()
fmt.Println("--------------------")
time.Sleep(time.Second)
}
}
func Test_defaultTimeWindow(t *testing.T) {
observer := getCurrentObserver(offsetWindow)
fmt.Println(observer)
a, b, c := nextTimeWindow(observer, rollingWindow)
fmt.Println(a, b, c)
nt := timestamp.Time(a)
fmt.Println(nt.Format(time.DateTime))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。