diff --git a/internal/internalpipe/snag.go b/internal/internalpipe/snag.go index f82eecb..3fedf13 100644 --- a/internal/internalpipe/snag.go +++ b/internal/internalpipe/snag.go @@ -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 } diff --git a/internal/internalpipe/yeet.go b/internal/internalpipe/yeet.go index e7a03cd..5866851 100644 --- a/internal/internalpipe/yeet.go +++ b/internal/internalpipe/yeet.go @@ -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 } @@ -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{}, } @@ -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) @@ -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) } diff --git a/pkg/pipe/interface.go b/pkg/pipe/interface.go index fc8f267..cb1e7ab 100644 --- a/pkg/pipe/interface.go +++ b/pkg/pipe/interface.go @@ -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. @@ -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 { @@ -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 } diff --git a/pkg/pipe/pipe.go b/pkg/pipe/pipe.go index 6bd213d..762ca12 100644 --- a/pkg/pipe/pipe.go +++ b/pkg/pipe/pipe.go @@ -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 diff --git a/pkg/pipe/pipenl.go b/pkg/pipe/pipenl.go index 9647e58..35ff38b 100644 --- a/pkg/pipe/pipenl.go +++ b/pkg/pipe/pipenl.go @@ -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