Skip to content

Commit

Permalink
fixed Yeti and Snag method structure for Piper and PiperNoLen
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Koss committed Nov 6, 2023
1 parent 3fe5550 commit 59e30e4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
4 changes: 1 addition & 3 deletions internal/internalpipe/snag.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package internalpipe

import "unsafe"

// Sang ads error handler to a current Pipe step.
func (p Pipe[T]) Snag(h ErrHandler) Pipe[T] {
// todo: think about NPE here
p.y.SnagPipe(unsafe.Pointer(p.prevP), h)
p.y.SnagPipe(p.prevP, h)
return p
}

Expand Down
8 changes: 4 additions & 4 deletions internal/internalpipe/yeet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ErrHandler func(error)
type Yeti struct {
Errs []error
Handlers []ErrHandler
Pipe2Hdlrs map[unsafe.Pointer][]ErrHandler
Pipe2Hdlrs map[uintptr][]ErrHandler
EMx *sync.Mutex
HMx *sync.Mutex
}
Expand All @@ -19,7 +19,7 @@ func NewYeti() *Yeti {
return &Yeti{
Errs: make([]error, 0),
Handlers: make([]ErrHandler, 0),
Pipe2Hdlrs: make(map[unsafe.Pointer][]ErrHandler),
Pipe2Hdlrs: make(map[uintptr][]ErrHandler),
EMx: &sync.Mutex{},
HMx: &sync.Mutex{},
}
Expand All @@ -35,7 +35,7 @@ func (y *Yeti) Snag(handler ErrHandler) {
y.Handlers = append(y.Handlers, handler)
}

func (y *Yeti) SnagPipe(p unsafe.Pointer, h ErrHandler) {
func (y *Yeti) SnagPipe(p uintptr, h ErrHandler) {
y.HMx.Lock()
if hdlrs, ok := y.Pipe2Hdlrs[p]; ok {
y.Pipe2Hdlrs[p] = append(hdlrs, h)
Expand All @@ -52,7 +52,7 @@ func (y *Yeti) Handle(p unsafe.Pointer) {

type yeti interface {
Yeet(err error)
SnagPipe(p unsafe.Pointer, h ErrHandler)
SnagPipe(p uintptr, h ErrHandler)
// TODO: Handle should be called after each Pipe function eval
Handle(p unsafe.Pointer)
}
6 changes: 3 additions & 3 deletions pkg/pipe/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Piper[T any] interface {
promicer[T]
eraser[Piper[any]]
snagger[Piper[T]]
yeti[Piper[T]]
yetyer[Piper[T]]
}

// PiperNoLen represents methods available to a Pipe type with no length determened.
Expand All @@ -39,7 +39,7 @@ type PiperNoLen[T any] interface {

eraser[PiperNoLen[any]]
snagger[PiperNoLen[T]]
yeti[PiperNoLen[T]]
yetyer[PiperNoLen[T]]
}

type paralleller[T, PiperT any] interface {
Expand Down Expand Up @@ -102,6 +102,6 @@ type snagger[PiperT any] interface {
Snag(func(error)) PiperT
}

type yeti[PiperT any] interface {
type yetyer[PiperT any] interface {
Yeti(y internalpipe.YeetSnag) PiperT
}
5 changes: 5 additions & 0 deletions pkg/pipe/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func (p *Pipe[T]) Snag(h func(error)) Piper[T] {
return &Pipe[T]{p.Pipe.Snag(internalpipe.ErrHandler(h))}
}

// Yeti links a yeti error handler to the Pipe.
func (p *Pipe[T]) Yeti(y internalpipe.YeetSnag) Piper[T] {
return &Pipe[T]{p.Pipe.Yeti(y)}
}

// Entrails is an out-of-Piper interface method to provide Map[T1 -> T2].
func (p *Pipe[T]) Entrails() *internalpipe.Pipe[T] {
return &p.Pipe
Expand Down
5 changes: 5 additions & 0 deletions pkg/pipe/pipenl.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func (p *PipeNL[T]) Snag(h func(error)) PiperNoLen[T] {
return &PipeNL[T]{p.Pipe.Snag(internalpipe.ErrHandler(h))}
}

// Yeti links a yeti error handler to the Pipe.
func (p *PipeNL[T]) Yeti(y internalpipe.YeetSnag) PiperNoLen[T] {
return &PipeNL[T]{p.Pipe.Yeti(y)}
}

// Entrails is an out of Piper interface method to provide Map[T1 -> T2].
func (p *PipeNL[T]) Entrails() *internalpipe.Pipe[T] {
return &p.Pipe
Expand Down

0 comments on commit 59e30e4

Please sign in to comment.