Skip to content

Commit

Permalink
refactor: move xsync package to github.com/fufuok/xsync@dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fufuok committed Jul 8, 2024
1 parent 5215e02 commit e49f9b9
Show file tree
Hide file tree
Showing 28 changed files with 10 additions and 7,464 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ type Daemon struct{ ... }

**官方版本: `v3.0.0` 已统一了调用方法并内置了 hasher 生成器, 不再需要之前的改动, 直接使用官方原版就好**

**如果要在 go1.18 以下使用, 可以使用: github.com/fufuok/[email protected]**

<details>
<summary>DOC</summary>

Expand Down Expand Up @@ -1001,6 +1003,7 @@ package main
import (
"encoding/json"
"fmt"
"sync/atomic"
"time"

"github.com/fufuok/utils"
Expand All @@ -1014,7 +1017,6 @@ import (
"github.com/fufuok/utils/xhash"
"github.com/fufuok/utils/xid"
"github.com/fufuok/utils/xjson/jsongen"
"github.com/fufuok/utils/xsync"
)

func main() {
Expand Down Expand Up @@ -1186,16 +1188,16 @@ func main() {
now = utils.WaitNextSecondWithTime()
fmt.Println("hour:minute:second.00*ms", now)

count := xsync.NewCounter()
count := int64(0)
bus := sched.New() // 默认并发数: runtime.NumCPU()
for i := 0; i < 30; i++ {
bus.Add(1)
bus.RunWithArgs(func(n ...interface{}) {
count.Add(int64(n[0].(int)))
atomic.AddInt64(&count, int64(n[0].(int)))
}, i)
}
bus.Wait()
fmt.Println("count:", count.Value()) // count: 435
fmt.Println("count:", atomic.LoadInt64(&count)) // count: 435

// 继续下一批任务
bus.Add(1)
Expand Down
8 changes: 4 additions & 4 deletions sched/examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ package main

import (
"fmt"
"sync/atomic"
"time"

"github.com/fufuok/utils/sched"
"github.com/fufuok/utils/xsync"
)

func main() {
count := xsync.NewCounter()
count := int64(0)
bus := sched.New() // 默认并发数: runtime.NumCPU()
for i := 0; i < 30; i++ {
bus.Add(1)
bus.RunWithArgs(func(n ...interface{}) {
count.Add(int64(n[0].(int)))
atomic.AddInt64(&count, int64(n[0].(int)))
}, i)
}
bus.Wait()
fmt.Println("count:", count.Value()) // count: 435
fmt.Println("count:", atomic.LoadInt64(&count)) // count: 435

// 继续下一批任务
bus.Add(1)
Expand Down
131 changes: 0 additions & 131 deletions xsync/BENCHMARKS.md

This file was deleted.

Loading

0 comments on commit e49f9b9

Please sign in to comment.