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

Method Get

pkg/queue/queue.go:55–85  ·  view source on GitHub ↗

Get retrieves and removes the next non-cancelled task from the queue, adding it to the running tasks. Blocks until a task is available or the queue is closed.

()

Source from the content-addressed store, hash-verified

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.
55func (tq *TaskQueue[T]) Get() (*Task[T], error) {
56 tq.mu.Lock()
57 defer tq.mu.Unlock()
58
59 for tq.tasks.Len() == 0 && !tq.closed {
60 tq.cond.Wait()
61 }
62
63 if tq.closed && tq.tasks.Len() == 0 {
64 return nil, fmt.Errorf("queue is closed and empty")
65 }
66
67 for tq.tasks.Len() > 0 {
68 element := tq.tasks.Front()
69 task := element.Value.(*Task[T])
70
71 tq.tasks.Remove(element)
72 task.element = nil
73
74 if !task.Cancelled() {
75 tq.runningTaskMap[task.ID] = task
76 return task, nil
77 }
78 }
79
80 if !tq.closed {
81 return tq.Get()
82 }
83
84 return nil, fmt.Errorf("queue is closed and empty")
85}
86
87// Done stops(cancels) and removes the task from the running tasks.
88func (tq *TaskQueue[T]) Done(taskID string) {

Callers 12

jsRegisterParserFunction · 0.45
api.goFile · 0.45
workerFunction · 0.45
ExecuteMethod · 0.45
TestCloseBehaviorFunction · 0.45
TestConcurrencySafetyFunction · 0.45
signRequestFunction · 0.45
AuthMiddlewareFunction · 0.45
ParseMessageLinkFunction · 0.45
GetFunction · 0.45
ParseMessageLinkFunction · 0.45
InitFunction · 0.45

Calls 3

CancelledMethod · 0.80
WaitMethod · 0.45
RemoveMethod · 0.45

Tested by 2

TestCloseBehaviorFunction · 0.36
TestConcurrencySafetyFunction · 0.36