mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-11 03:06:51 +02:00
replace unnecessary Task interface with struct
This commit is contained in:
@@ -26,7 +26,7 @@ type DirWatcher struct {
|
||||
eventCh chan Event
|
||||
errCh chan E.Error
|
||||
|
||||
task task.Task
|
||||
task *task.Task
|
||||
}
|
||||
|
||||
// NewDirectoryWatcher returns a DirWatcher instance.
|
||||
@@ -37,7 +37,7 @@ type DirWatcher struct {
|
||||
//
|
||||
// Note that the returned DirWatcher is not ready to use until the goroutine
|
||||
// started by NewDirectoryWatcher has finished.
|
||||
func NewDirectoryWatcher(callerSubtask task.Task, dirPath string) *DirWatcher {
|
||||
func NewDirectoryWatcher(callerSubtask *task.Task, dirPath string) *DirWatcher {
|
||||
//! subdirectories are not watched
|
||||
w, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
|
||||
type (
|
||||
EventQueue struct {
|
||||
task task.Task
|
||||
task *task.Task
|
||||
queue []Event
|
||||
ticker *time.Ticker
|
||||
flushInterval time.Duration
|
||||
onFlush OnFlushFunc
|
||||
onError OnErrorFunc
|
||||
}
|
||||
OnFlushFunc = func(flushTask task.Task, events []Event)
|
||||
OnFlushFunc = func(flushTask *task.Task, events []Event)
|
||||
OnErrorFunc = func(err E.Error)
|
||||
)
|
||||
|
||||
@@ -38,7 +38,7 @@ const eventQueueCapacity = 10
|
||||
// but the onFlush function can return earlier (e.g. run in another goroutine).
|
||||
//
|
||||
// If task is canceled before the flushInterval is reached, the events in queue will be discarded.
|
||||
func NewEventQueue(parent task.Task, flushInterval time.Duration, onFlush OnFlushFunc, onError OnErrorFunc) *EventQueue {
|
||||
func NewEventQueue(parent *task.Task, flushInterval time.Duration, onFlush OnFlushFunc, onError OnErrorFunc) *EventQueue {
|
||||
return &EventQueue{
|
||||
task: parent.Subtask("event queue"),
|
||||
queue: make([]Event, 0, eventQueueCapacity),
|
||||
@@ -53,7 +53,7 @@ func (e *EventQueue) Start(eventCh <-chan Event, errCh <-chan E.Error) {
|
||||
if common.IsProduction {
|
||||
origOnFlush := e.onFlush
|
||||
// recover panic in onFlush when in production mode
|
||||
e.onFlush = func(flushTask task.Task, events []Event) {
|
||||
e.onFlush = func(flushTask *task.Task, events []Event) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
e.onError(E.New("recovered panic in onFlush").
|
||||
|
||||
@@ -36,7 +36,7 @@ type (
|
||||
|
||||
metric *metrics.Gauge
|
||||
|
||||
task task.Task
|
||||
task *task.Task
|
||||
}
|
||||
)
|
||||
|
||||
@@ -61,7 +61,7 @@ func (mon *monitor) ContextWithTimeout(cause string) (ctx context.Context, cance
|
||||
}
|
||||
|
||||
// Start implements task.TaskStarter.
|
||||
func (mon *monitor) Start(routeSubtask task.Task) E.Error {
|
||||
func (mon *monitor) Start(routeSubtask *task.Task) E.Error {
|
||||
mon.service = routeSubtask.Parent().Name()
|
||||
mon.task = routeSubtask
|
||||
|
||||
|
||||
Reference in New Issue
Block a user