Documentation
¶
Index ¶
- type AsyncTask
- type AsyncTaskResult
- type AsyncTaskResultStore
- type AsyncWorkerPool
- func (w *AsyncWorkerPool) GetFirstError() error
- func (w *AsyncWorkerPool) Start(initFn func(res any) error, stopFn func(resource any) error)
- func (w *AsyncWorkerPool) Stop()
- func (w *AsyncWorkerPool) Submit(fn func(res any) (any, error)) (uint64, error)
- func (w *AsyncWorkerPool) SubmitContext(ctx context.Context, fn func(res any) (any, error)) (uint64, error)
- func (w *AsyncWorkerPool) Wait(jobID uint64) (*AsyncTaskResult, error)
- type ThreadPoolExecutor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncTaskResult ¶
AsyncTaskResult holds the result of a AsyncTask execution.
type AsyncTaskResultStore ¶
type AsyncTaskResultStore struct {
// contains filtered or unexported fields
}
AsyncTaskResultStore manages the storage and retrieval of AsyncTaskResults.
func NewAsyncTaskResultStore ¶
func NewAsyncTaskResultStore() *AsyncTaskResultStore
NewAsyncTaskResultStore creates a new AsyncTaskResultStore.
func (*AsyncTaskResultStore) GetNextJobID ¶
func (s *AsyncTaskResultStore) GetNextJobID() uint64
GetNextJobID atomically increments and returns a new unique job ID.
func (*AsyncTaskResultStore) Stop ¶
func (s *AsyncTaskResultStore) Stop()
Stop signals the AsyncTaskResultStore to stop processing new waits.
func (*AsyncTaskResultStore) Store ¶
func (s *AsyncTaskResultStore) Store(result *AsyncTaskResult)
Store saves a AsyncTaskResult in the store and signals any waiting goroutines.
func (*AsyncTaskResultStore) Wait ¶
func (s *AsyncTaskResultStore) Wait(jobID uint64) (*AsyncTaskResult, error)
Wait blocks until the result for the given jobID is available and returns it. The result is removed from the internal map after being retrieved.
type AsyncWorkerPool ¶
type AsyncWorkerPool struct {
*AsyncTaskResultStore // Embed the result store
// contains filtered or unexported fields
}
AsyncWorkerPool runs tasks in a dedicated OS thread with a CUDA context.
func NewAsyncWorkerPool ¶
func NewAsyncWorkerPool(nthread uint, createResource func() (any, error), cleanupResource func(any)) *AsyncWorkerPool
NewAsyncWorkerPool creates a new AsyncWorkerPool.
func (*AsyncWorkerPool) GetFirstError ¶
func (w *AsyncWorkerPool) GetFirstError() error
GetFirstError returns the first internal error encountered by the worker.
func (*AsyncWorkerPool) Start ¶
func (w *AsyncWorkerPool) Start(initFn func(res any) error, stopFn func(resource any) error)
Start begins the worker's execution loop.
func (*AsyncWorkerPool) Stop ¶
func (w *AsyncWorkerPool) Stop()
Stop signals the worker to terminate and waits for it to finish.
func (*AsyncWorkerPool) Submit ¶
Submit sends a task to the worker. Blocks if the task buffer is full (buffer size = nthread) until either:
- the worker accepts the task — returns (jobID, nil), or
- the pool is stopped via Stop / signal / internal error — returns (0, error).
Callers that cannot tolerate unbounded blocking on a saturated buffer must use SubmitContext with a context.Context deadline.
func (*AsyncWorkerPool) SubmitContext ¶
func (w *AsyncWorkerPool) SubmitContext(ctx context.Context, fn func(res any) (any, error)) (uint64, error)
SubmitContext is Submit with a caller-supplied deadline / cancellation signal. Returns the context's error if it fires before the worker accepts the task. The pool-stopped path still wins over a still-live context — callers should treat that as "drop the task" the same way.
func (*AsyncWorkerPool) Wait ¶
func (w *AsyncWorkerPool) Wait(jobID uint64) (*AsyncTaskResult, error)
Wait blocks until the result for the given jobID is available and returns it. The result is removed from the internal map after being retrieved.
type ThreadPoolExecutor ¶
type ThreadPoolExecutor struct {
// contains filtered or unexported fields
}
func NewThreadPoolExecutor ¶
func NewThreadPoolExecutor(nthreads int) ThreadPoolExecutor