Skip to content

thoughts on supporting functions that return errors and handling pancis #2

Description

@dvic

What are your thoughts on adding support for getting errors back and thereby also handling panics, e.g.,

// RunErr runs a function of type func() error in a new goroutine.
// The returned channel is closed when f returns.
func (r *Runner) RunErr(f func() error) <-chan error {
	done := make(chan error, 1)
	r.wg.Add(1)
	go func() {
		var ret error
		defer func() {
			rec := recover()
			if recErr, ok := rec.(error); ok {
				ret = recErr
			} else if rec != nil {
				ret = errors.New(fmt.Sprintf("panic: %+v", rec))
			}
			done <- ret
			close(done)
			r.wg.Done()
		}()
		ret = f()
	}()
	return done
}

(and also RunErrContext and RunErrOtherContext)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions