singledo - Singleton Execution
Overview
The singledo module ensures that operations run only once, preventing duplicate calculations or executions.
Types
Single[T]
Generic singleton executor.
Constructor
NewSingleT
Create new singleton executor.
Parameters:
wait- Wait duration before allowing re-execution
Returns:
- Singleton executor instance
Example:
Methods
Do()
Execute function with singleton guarantee.
Parameters:
fn- Function to execute
Returns:
- Result from function
- Error from function
Behavior:
- If within wait duration, returns cached result
- Otherwise, executes function and caches result
Example:
Reset()
Reset the singleton executor.
Example:
Usage Patterns
Expensive Calculations
Data Loading
Configuration Loading
Best Practices
Wait Duration
Error Handling
Related Documentation
- routine - Goroutine management
- wait - Flow control
- API Documentation
- Module Overview