Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.18
go-version: '1.24'

- name: Build
run: go build -v ./...
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,19 @@ https://godoc.org/go.tempura.ink/co

## Getting started

Navigate to your project base and `go get go.tempura.ink/co`
Navigate to your project base and run:

```bash
go get go.tempura.ink/co
```

If you're behind a firewall or need to fetch without a proxy:

```bash
GOSUMDB=off GOPROXY=direct go get go.tempura.ink/co
```

**Requirements**: Go 1.22 or later

## Examples

Expand Down Expand Up @@ -155,7 +167,7 @@ go func() {

result := [][]int{}
for data := range bList.Iter() {
result = append(acturesultal, data)
result = append(result, data)
}
```

Expand Down
2 changes: 1 addition & 1 deletion ds/pool/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (w *Worker[K]) startListening() {
for {
yeildCost := 1
for !w.quit {
currentPendingJob := w.pool.pendingJob
currentPendingJob := atomic.LoadUint32(&w.pool.pendingJob)
if currentPendingJob > 0 {
if atomic.CompareAndSwapUint32(&w.pool.pendingJob, currentPendingJob, currentPendingJob-1) {
break
Expand Down
9 changes: 6 additions & 3 deletions ds/queue/multi_receiver_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (q *MultiReceiverQueue[K]) Count() int {
func (q *MultiReceiverQueue[K]) Enqueue(v K) {
n := q.nodeCache.Get().(*node[K])
n.value = v
atomic.StoreUint32(&n.dequeued, 0)
atomic.StorePointer(&n.next, nil)

for {
tail := load[K](&q.tail)
Expand All @@ -72,7 +74,8 @@ func (q *MultiReceiverQueue[K]) Enqueue(v K) {

func (q *MultiReceiverQueue[K]) purgeNode(n *node[K]) {
atomic.AddInt32(&q.size, -1)
n.dequeued, n.next = 0, nil
atomic.StoreUint32(&n.dequeued, 0)
atomic.StorePointer(&n.next, nil)
q.nodeCache.Put(n) // head is dead, put back to pool
}

Expand All @@ -94,7 +97,7 @@ func (q *MultiReceiverQueue[K]) dequeue(r *QueueReceiver[K]) K {
// tail is falling behind. try to advance it
cas(&q.tail, tail, next)

} else if next.dequeued == r.receiver {
} else if atomic.LoadUint32(&next.dequeued) == r.receiver {
if next == nil { // is queue empty?
return *new(K)
}
Expand All @@ -109,9 +112,9 @@ func (q *MultiReceiverQueue[K]) dequeue(r *QueueReceiver[K]) K {
if rnext == nil { // is queue empty?
return *new(K)
}
v := rnext.value

if cas(&r.node, rhead, rnext) {
v := rnext.value // Read value after successful CAS
if atomic.AddUint32(&rnext.dequeued, 1) == q.receiver {
// where the receiver is the last receiver in the queue
if cas(&q.head, rhead, rnext) {
Expand Down
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module go.tempura.ink/co

go 1.18
go 1.24.0

toolchain go1.24.7

require (
github.com/smartystreets/goconvey v1.7.2
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb
github.com/smartystreets/goconvey v1.8.1
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93
)

require (
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/smarty/assertions v1.15.0 // indirect
)
23 changes: 8 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
github.com/Jeffail/tunny v0.1.4 h1:chtpdz+nUtaYQeCKlNBg6GycFF/kGVHOr6A3cmzTJXs=
github.com/Jeffail/tunny v0.1.4/go.mod h1:P8xAx4XQl0xsuhjX1DtfaMDCSuavzdb2rwbd0lk+fvo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb h1:pC9Okm6BVmxEw76PUu0XUbOTQ92JX11hfvqTjAV3qxM=
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 h1:fQsdNF2N+/YewlRZiricy4P1iimyPKZ/xwniHj8Q2a0=
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93/go.mod h1:EPRbTFwzwjXj9NpYyyrvenVh9Y+GFeEvMNh7Xuz7xgU=
2 changes: 1 addition & 1 deletion parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (d *parallel[R]) receiveValue(seq uint64, val R) {

func (d *parallel[R]) GetData() []R {
if !d.ifPersistentData {
panic("co/paralle error when get data: persistent data mode is not set")
panic("co/parallel error when get data: persistent data mode is not set")
}
return d.storedData.list
}
Expand Down
Loading