Refactored crawler to use task dispatcher

This commit is contained in:
James Mills
2021-02-02 13:13:12 +10:00
parent 4970b16d61
commit 26df009e8f
13 changed files with 578 additions and 51 deletions

25
internal/func_task.go Normal file
View File

@@ -0,0 +1,25 @@
package internal
import "fmt"
type FuncTask struct {
*BaseTask
f func() error
}
func NewFuncTask(f func() error) *FuncTask {
return &FuncTask{
BaseTask: NewBaseTask(),
f: f,
}
}
func (t *FuncTask) String() string { return fmt.Sprintf("%T: %s", t, t.ID()) }
func (t *FuncTask) Run() error {
defer t.Done()
t.SetState(TaskStateRunning)
return t.f()
}