mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-10-25 11:20:21 +08:00
26 lines
360 B
Go
26 lines
360 B
Go
package task
|
|
|
|
import (
|
|
. "m7s.live/m7s/v5/pkg/util"
|
|
)
|
|
|
|
type ManagerItem[K comparable] interface {
|
|
ITask
|
|
GetKey() K
|
|
}
|
|
|
|
type Manager[K comparable, T ManagerItem[K]] struct {
|
|
MarcoLongTask
|
|
Collection[K, T]
|
|
}
|
|
|
|
func (m *Manager[K, T]) Add(ctx T) {
|
|
ctx.OnStart(func() {
|
|
m.Collection.Add(ctx)
|
|
})
|
|
ctx.OnDispose(func() {
|
|
m.Remove(ctx)
|
|
})
|
|
m.AddTask(ctx)
|
|
}
|