Refactored crawler to use task dispatcher
This commit is contained in:
25
internal/func_task.go
Normal file
25
internal/func_task.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user