Import path:
gitlab.soludian.com/soludian/fountain/libs/base/fgo
fgo
import "gitlab.soludian.com/soludian/fountain/libs/base/fgo"Index
Constants
DefaultPoolSize giới hạn tổng số background task chạy đồng thời cho default pool. Đủ lớn để không tạo back-pressure ở tải bình thường, đủ nhỏ để chặn goroutine explosion ở tải đột biến (1 service phát sinh hàng nghìn fire-and-forget tasks).
const DefaultPoolSize = 256func InFlight
func InFlight() int64InFlight trả về số task đang chạy trên default pool.
func Run
func Run(name string, fn func())Run sử dụng default pool. Xem Pool.Run.
type Pool
Pool là một bounded worker pool dựa trên semaphore.
type Pool struct {
// contains filtered or unexported fields
}func NewPool
func NewPool(capacity int) *PoolNewPool tạo Pool mới với capacity cho trước. Có thể sử dụng "github.com/alitto/pond/v2" để có thêm tính năng như timeout, retry, v.v. nhưng ở đây implement đơn giản để tránh phụ thuộc ngoài.
func (*Pool) InFlight
func (p *Pool) InFlight() int64InFlight trả về số task đang chạy. Hữu ích cho monitoring/metrics.
func (*Pool) Run
func (p *Pool) Run(name string, fn func())Run chạy fn trong goroutine có giới hạn concurrency.
- Nếu pool còn slot: acquire ngay, spawn goroutine, return ngay.
- Nếu pool đầy: block caller cho tới khi có slot trống (back-pressure).
- Recover panic để 1 task lỗi không crash service.
Tham số `name` chỉ dùng cho logging khi panic xảy ra.
Generated by gomarkdoc