Skip to content

Commit

Permalink
export Queue
Browse files Browse the repository at this point in the history
  • Loading branch information
nikandfor committed Jan 7, 2024
1 parent d28d1d5 commit 87b254e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This is all without timeouts, additional goroutines, allocations, and channels.

```
// General pattern is
// QueueIn -> Enter -> defer Exit -> Commit/Cancel/return/panic
// Queue.In -> Enter -> defer Exit -> Commit/Cancel/return/panic
var sum int
Expand All @@ -42,7 +42,7 @@ for j := 0; j < N; j++ {
go func(j int) {
ctx := context.WithValue(ctx, workerID{}, j) // can be obtained in Coordinator.Commit
bc.QueueIn() // let others know we are going to join
bc.Queue().In() // let others know we are going to join
data := 1 // prepare data
Expand Down
4 changes: 3 additions & 1 deletion batch4.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func New[Res any](f func(ctx context.Context) (Res, error)) *Coordinator[Res] {
}
}

func (c *Coordinator[Res]) QueueIn() { c.queue.In() }
func (c *Coordinator[Res]) Queue() *Queue {
return &c.locs.queue
}

func (c *Coordinator[Res]) Enter(blocking bool) int {
c.mu.Lock()
Expand Down
6 changes: 3 additions & 3 deletions batch4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestCoordinatorSmoke(tb *testing.T) {
i := i

func() {
bc.QueueIn()
bc.Queue().In()

runtime.Gosched()

Expand Down Expand Up @@ -107,7 +107,7 @@ func TestCoordinatorAllCases(tb *testing.T) {
}()
}

bc.QueueIn()
bc.Queue().In()

runtime.Gosched()

Expand Down Expand Up @@ -184,7 +184,7 @@ func BenchmarkCoordinator(tb *testing.B) {
tb.RunParallel(func(tb *testing.PB) {
for tb.Next() {
func() {
bc.QueueIn()
bc.Queue().In()

// runtime.Gosched()

Expand Down
2 changes: 1 addition & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *Service) commit(ctx context.Context) (int, error) {
}

func (s *Service) DoWork(ctx context.Context, data int) (int, error) {
s.bc.QueueIn() // let others know we are going to join
s.bc.Queue().In() // let others know we are going to join

_ = data // prepare data

Expand Down
4 changes: 3 additions & 1 deletion multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func NewMulti[Res any](n int, f func(ctx context.Context, coach int) (Res, error
}
}

func (c *Multi[Res]) QueueIn() { c.queue.In() }
func (c *Multi[Res]) Queue() *Queue {
return &c.locs.queue
}

func (c *Multi[Res]) Enter(blocking bool) (coach, idx int) {
c.mu.Lock()
Expand Down
2 changes: 1 addition & 1 deletion multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestMulti(tb *testing.T) {
}()
}

bc.QueueIn()
bc.Queue().In()

runtime.Gosched()

Expand Down

0 comments on commit 87b254e

Please sign in to comment.