routine - Goroutine Management
Overview
The routine module provides goroutine management utilities including worker pools, task scheduling, and panic recovery.
Functions
Go()
Execute function in a goroutine with panic recovery.
Parameters:
f- Function to execute
Behavior:
- Executes function in a goroutine
- Logs errors if function returns error
- Automatically manages trace IDs
Example:
GoWithRecover()
Execute function in a goroutine with full panic recovery.
Parameters:
f- Function to execute
Behavior:
- Executes function in a goroutine
- Catches panics and logs stack trace
- Logs errors if function returns error
Example:
GoWithMustSuccess()
Execute function in a goroutine with panic on error.
Parameters:
f- Function to execute
Behavior:
- Executes function in a goroutine
- Exits process if function returns error
Example:
AddBeforeRoutine()
Add callback to execute before goroutine starts.
Parameters:
f- Callback function
Example:
AddAfterRoutine()
Add callback to execute after goroutine completes.
Parameters:
f- Callback function
Example:
Usage Patterns
Background Tasks
Error Handling
Task Scheduling
Best Practices
Error Recovery
Related Documentation
- wait - Flow control
- hystrix - Circuit breaker
- API Documentation
- Module Overview