# thread **Repository Path**: xgo-core/thread ## Basic Information - **Project Name**: thread - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-14 - **Last Updated**: 2026-06-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # XGo Thread `gitee.com/xgo-core/thread` 提供用于安全处理 goroutine 的小工具。 [English Documentation](README.md) ## 主要功能 - 在新的 goroutine 中执行函数。 - 自动恢复 goroutine 内部发生的 panic。 - 忽略 nil 函数。 - 只依赖 Go 标准库。 ## 安装 ```sh go get gitee.com/xgo-core/thread ``` ## 使用示例 ### 启动安全协程 ```go package main import "gitee.com/xgo-core/thread" func main() { thread.Go(func() { // 在这里执行后台任务。 }) } ``` ### 恢复协程内的 Panic ```go package main import "gitee.com/xgo-core/thread" func main() { thread.Go(func() { panic("unexpected error") }) // panic 会在 goroutine 内部被恢复。 } ``` ## API | API | 说明 | | --- | --- | | `Go(func())` | 在 goroutine 中执行函数,并恢复函数内部发生的 panic。 | ## 注意事项 `Go` 可以避免后台任务中的 panic 导致进程崩溃,但不会上报被恢复的 panic。如果调用方需要日志、指标、重试或错误传递,请在传入 `Go` 的函数内部自行处理。