MCPcopy Create free account
hub / github.com/krau/SaveAny-Bot / Add

Method Add

pkg/queue/queue.go:29–51  ·  view source on GitHub ↗
(task *Task[T])

Source from the content-addressed store, hash-verified

27}
28
29func (tq *TaskQueue[T]) Add(task *Task[T]) error {
30 tq.mu.Lock()
31 defer tq.mu.Unlock()
32
33 if tq.closed {
34 return errors.New("queue is closed")
35 }
36
37 if _, exists := tq.taskMap[task.ID]; exists {
38 return fmt.Errorf("task with ID %s already exists", task.ID)
39 }
40
41 if task.Cancelled() {
42 return fmt.Errorf("task %s has been cancelled", task.ID)
43 }
44
45 element := tq.tasks.PushBack(task)
46 task.element = element
47 tq.taskMap[task.ID] = task
48
49 tq.cond.Signal()
50 return nil
51}
52
53// Get retrieves and removes the next non-cancelled task from the queue, adding it to the running tasks.
54// Blocks until a task is available or the queue is closed.

Callers 15

AddTaskFunction · 0.80
ExecuteMethod · 0.80
processElementMethod · 0.80
ExecuteMethod · 0.80
processResourceMethod · 0.80
WriteAtMethod · 0.80
WriteMethod · 0.80
ExecuteMethod · 0.80
processLinkMethod · 0.80
processElementMethod · 0.80
GetPageMethod · 0.80
TestAddAndLengthFunction · 0.80

Calls 1

CancelledMethod · 0.80

Tested by 6

TestAddAndLengthFunction · 0.64
TestDuplicateAddFunction · 0.64
TestConcurrencySafetyFunction · 0.64