Pad/internal/io/pool/result.go
Greg Pomerantz 6a43e3c0db Add e2e test harness for testing editor logic without Gio display
- internal/test/e2e/: FrameCapture, Harness, ElementAssertions, helpers
- internal/editor/logic.go: Add done channel and Done() method for graceful shutdown
- internal/editor/mock_setup.go: Mock filesystem for tests
- internal/browser/: Browser layout and search logic
- internal/io/: Worker pool for async tasks
- Update architecture docs and spec
2026-05-31 08:56:30 -04:00

74 lines
1.8 KiB
Go

package pool
import "time"
// Result is posted back to the logic goroutine when a task completes.
// Results are immutable and contain all information needed to apply
// the task outcome to state.
type Result struct {
TaskID string `json:"task_id"`
TaskType TaskType `json:"task_type"`
Success bool `json:"success"`
Data any `json:"data,omitempty"`
Error error `json:"error,omitempty"`
Timestamp time.Time `json:"timestamp"`
DirPath string `json:"dir_path,omitempty"`
}
// IsSuccess returns true if the task completed successfully.
func (r Result) IsSuccess() bool {
return r.Success && r.Error == nil
}
// IsError returns true if the task failed.
func (r Result) IsError() bool {
return !r.Success || r.Error != nil
}
// IsBrowserResult returns true if this result is for a browser task.
func (r Result) IsBrowserResult() bool {
switch r.TaskType {
case TypeReadDir, TypeBuildIndex, TypeLoadIndex, TypeLoadPages, TypeStatDir:
return true
default:
return false
}
}
// IsFileResult returns true if this result is for a file operation.
func (r Result) IsFileResult() bool {
switch r.TaskType {
case TypeReadFile, TypeWriteFile, TypeStatFile:
return true
default:
return false
}
}
// IsCacheResult returns true if this result is for a cache operation.
func (r Result) IsCacheResult() bool {
switch r.TaskType {
case TypeWriteCache, TypeReadCache, TypeInvalidate:
return true
default:
return false
}
}
// IsStateResult returns true if this result is for state persistence.
func (r Result) IsStateResult() bool {
switch r.TaskType {
case TypeSaveState, TypeSaveUndo:
return true
default:
return false
}
}
// Duration returns the time taken for this result (for benchmarking).
func (r Result) Duration() time.Duration {
// In production, this would be set by the worker.
// For now, returns zero.
return 0
}