conc icon indicating copy to clipboard operation
conc copied to clipboard

Add a `Wait()`-like method that returns a caught panic

Open camdencheek opened this issue 2 years ago • 8 comments

Re-panicking is not ideal for every situation. Sometimes, in the case of a panic, a user will want to handle the panic manually. It's possible to recover() the propagated panic, but that's extra work for the user and you lose the type information that the panic value is a RecoveredPanic.

We should add a method like WaitSafe() that returns a *RecoveredPanic if a panic was caught.

Open questions:

  • What to call it? WaitSafe, SafeWait, WaitAndRecover all come to mind
  • Do we add this just to WaitGroup, or also add it to each of the .*Pool types?

camdencheek avatar Jan 07 '23 21:01 camdencheek

I would like to give this a shot over the next day or two if it's not urgent

jakecorrenti avatar Jan 07 '23 22:01 jakecorrenti

All yours -- have fun!

camdencheek avatar Jan 07 '23 23:01 camdencheek

something want to say about this.

now : // Wait will block until all goroutines spawned with Go exit and will // propagate any panics spawned in a child goroutine. func (h *WaitGroup) Wait() { h.wg.Wait()

// Propagate a panic if we caught one from a child goroutine
h.pc.Repanic()

}

i think : func (h *WaitGroup) safeWait() { h.wg.Wait()

// Propagate a panic if we caught one from a child goroutine
//h.pc.Repanic()

}

maybe give the choice to the user: func (h *WaitGroup) Wait() { h.wg.Wait()

    return h.pc

}

WTF is now "safe" use .

pc.Try( wg.Wait() )


as the golang design about log

func Println(v ...any) { if atomic.LoadInt32(&std.isDiscard) != 0 { return } std.Output(2, fmt.Sprintln(v...)) }

func Fatal(v ...any) { std.Output(2, fmt.Sprint(v...)) os.Exit(1) }

i agree with the panic should be process. but give the choice to user.

welldonexing avatar Jan 08 '23 11:01 welldonexing

I'm actually going to put this back up for others to take on, I took too many things on at once... Sorry for the inconvenience

jakecorrenti avatar Jan 10 '23 16:01 jakecorrenti

No problem, thanks for letting us know 👍

camdencheek avatar Jan 10 '23 16:01 camdencheek

I don't mind giving this a shot if you don't mind.

We should add a method like WaitSafe() that returns a *RecoveredPanic if a panic was caught.

I'll attempt this approach ☝️ unless you would prefer another.

craigpastro avatar Jan 11 '23 03:01 craigpastro

Go for it! Let me know if you have any questions

camdencheek avatar Jan 11 '23 07:01 camdencheek

Cool. Thank you!

Super nice project by the way!

craigpastro avatar Jan 11 '23 18:01 craigpastro