longpanic

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

package longpanic defines `Go` func that creates goroutine with defer that waits for somebody to call `RecoverFromPanic` or panics after timeout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go

func Go(fn func())

Go runs fn in a different goroutine with defer statement that: 1. Recovers from panic 2. Waits for somebody to call `RecoverFromPanic` or timeout 3. Panics if nobody calls `RecoverFromPanic`

func RecoverFromPanic

func RecoverFromPanic()

RecoverFromPanic is a signal to not wait for the panic and tries to continue the execution.

func SetOnPanicHandler added in v0.5.7

func SetOnPanicHandler(cb func(err error))

func SetTimeout

func SetTimeout(timeout time.Duration)

SetTimeout set the timeout after the program panics.

func WithRecover

func WithRecover(fn func())

WithRecover runs fn with defer statement that: 1. Recovers from panic 2. Waits for somebody to call `RecoverFromPanic` or timeout 3. Panics if nobody calls `RecoverFromPanic`

Types

type LongPanic

type LongPanic struct {
	// contains filtered or unexported fields
}

LongPanic is a struct that holds an atomic and a timeout after a defer fn will panic.

func NewLongPanic

func NewLongPanic(timeout time.Duration) *LongPanic

NewLongPanic creates LongPanic.

func (*LongPanic) Go

func (l *LongPanic) Go(fn func())

Go runs fn in a different goroutine with defer statement that: 1. Recovers from panic 2. Waits for somebody to call `RecoverFromPanic` or timeout 3. Panics if nobody calls `RecoverFromPanic`

func (*LongPanic) RecoverFromPanic

func (l *LongPanic) RecoverFromPanic()

RecoverFromPanic is a signal to not wait for the panic and tries to continue the execution.

func (*LongPanic) SetOnPanicHandler added in v0.5.7

func (l *LongPanic) SetOnPanicHandler(cb func(err error))

SetOnPanicHandler setups callback when panic happened.

func (*LongPanic) WithRecover

func (l *LongPanic) WithRecover(fn func())

WithRecover runs fn with defer statement that: 1. Recovers from panic 2. Waits for somebody to call `RecoverFromPanic` or timeout 3. Panics if nobody calls `RecoverFromPanic`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL