Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager[Meta any] struct { // OnTaskAdded is called immediately after calling Run(). You can use this for logging, metrics or other purposes. OnTaskAdded func(ctx context.Context, meta Meta) // OnTaskSucceeded is called immediately after Task returns. You can use this for logging, metrics or other purposes. OnTaskSucceeded func(ctx context.Context, meta Meta) // OnTaskFailed is called immediately after Task returns with an error. You can use this for logging, metrics or other // purposes. OnTaskFailed func(ctx context.Context, meta Meta, err error) // contains filtered or unexported fields }
Manager keeps track of scheduled goroutines and provides mechanisms to wait for them to finish. `Meta` is whatever you wish to associate with this task, usually something that will help you keep track of the tasks.
This is useful in context of HTTP servers, where a customer request may result in some kind of background processing activity that should not block the response and you schedule a goroutine to handle it. However, if your server receives a termination signal and you do not wait for these goroutines to finish, the goroutines will be killed before they can run to completion. This package is not a replacement for a proper task queue system but it is a great package to schedule the queue jobs without the customer waiting for that to happen while at the same time being able to wait for all those goroutines to finish before allowing the process to exit.
func NewManager ¶
NewManager creates a new instance of Manager with the provided generic type for the metadata argument.