sourcegraph / conc

Better structured concurrency for go

Home Page:https://about.sourcegraph.com/blog/building-conc-better-structured-concurrency-for-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

camdencheek opened this issue · 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?

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

All yours -- have fun!

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.

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

No problem, thanks for letting us know 👍

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.

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

Cool. Thank you!

Super nice project by the way!