xroutine

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SafeRoutine

func SafeRoutine(f func(...interface{}), args ...interface{})

SafeRoutine 调用 recover() 安全执行 goroutine,避免内部 panic 导致进程崩溃。若内部发生 panic,则会打印到日志中。

注意:该方法对 log.Fatal 系列方法无效!

- `f` goroutine 中要执行的函数(建议不要在该函数中使用上下文参数,而通过 `args` 传入,避免闭包问题) - `args` goroutine 中要传入的参数

func SafeRoutineChan

func SafeRoutineChan(c chan<- error, f func(...interface{}), args ...interface{})

SafeRoutineChan 调用 recover() 安全执行 goroutine,避免内部 panic 导致进程崩溃。 若内部发生 panic,则会写入 `chan` ,随后关闭该通道。

执行完毕未发生 panic 也会关闭通道。

注意:该方法对 log.Fatal 系列方法无效!

- `c` 要获取内部错误的通道

- `f` goroutine 中要执行的函数(建议不要在该函数中使用上下文参数,而通过 `args` 传入,避免闭包问题)

- `args` goroutine 中要传入的参数

Types

This section is empty.

Jump to

Keyboard shortcuts

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