feat: remove and clear task
This commit is contained in:
@ -72,8 +72,16 @@ func (tm *Manager[K]) Cancel(tid K) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tm *Manager[K]) Remove(tid K) {
|
||||
func (tm *Manager[K]) Remove(tid K) error {
|
||||
t, ok := tm.Get(tid)
|
||||
if !ok {
|
||||
return errors.WithStack(ErrTaskNotFound)
|
||||
}
|
||||
if !t.Done() {
|
||||
return errors.WithStack(ErrTaskRunning)
|
||||
}
|
||||
tm.tasks.Delete(tid)
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveAll removes all tasks from the manager, this maybe shouldn't be used
|
||||
@ -110,6 +118,10 @@ func (tm *Manager[K]) ListDone() []*Task[K] {
|
||||
return tm.GetByStates(SUCCEEDED, CANCELED, ERRORED)
|
||||
}
|
||||
|
||||
func (tm *Manager[K]) ClearDone() {
|
||||
tm.RemoveByStates(SUCCEEDED, CANCELED, ERRORED)
|
||||
}
|
||||
|
||||
func NewTaskManager[K comparable](maxWorker int, updateID ...func(*K)) *Manager[K] {
|
||||
tm := &Manager[K]{
|
||||
tasks: generic_sync.MapOf[K, *Task[K]]{},
|
||||
|
Reference in New Issue
Block a user