Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nikandfor committed Jan 6, 2024
1 parent c4a7e8b commit 1362479
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions batch3.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,21 @@ func (c *Controller[Res]) commit(ctx context.Context, err error) (Res, error) {
again:
if err != nil || atomic.LoadInt32(&c.queue) == 0 {
c.cnt = -c.cnt
c.ready = true

if ep, ok := err.(PanicError); ok {
c.ready = true
c.err = err
panic(ep.Panic)
} else if err != nil {
c.ready = true
c.err = err
} else {
func() {
var res Res
var err error

defer func() {
c.ready = true
c.res, c.err = res, err

if p := recover(); p != nil {
Expand Down Expand Up @@ -260,8 +262,15 @@ func (b *Batch[Res]) Rollback(ctx context.Context, err error) (Res, error) {
return b.c.commit(ctx, err)
}

func AsPanicError(err error) (PanicError, bool) {
var pe PanicError

return pe, errors.As(err, &pe)
}

func (e PanicError) Error() string {
return fmt.Sprintf("panic: %v", e.Panic)
}

func (noCopy) Lock() {}
func (*noCopy) Lock() {}
func (*noCopy) Unlock() {}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module nikand.dev/go/batch

go 1.18

retract v0.4.0 // has a bug
5 changes: 4 additions & 1 deletion multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func (c *Multi[Res]) Enter(blocking bool) (b Batch[Res], coach, index int) {
for coach := range c.cs {
b, idx := c.cs[coach].Enter(false)
if idx >= 0 {
return b, coach, idx
return Batch[Res]{
c: b.c,
state: b.state,
}, coach, idx
}
}

Expand Down

0 comments on commit 1362479

Please sign in to comment.