Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions internal/project/background/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package background
import (
"context"
"sync"
"sync/atomic"
)

// Queue manages background tasks execution
type Queue struct {
wg sync.WaitGroup
mu sync.RWMutex
closed bool
closed atomic.Bool
}

// NewQueue creates a new background queue for managing background tasks execution.
Expand All @@ -18,12 +18,9 @@ func NewQueue() *Queue {
}

func (q *Queue) Enqueue(ctx context.Context, fn func(context.Context)) {
q.mu.RLock()
if q.closed {
q.mu.RUnlock()
if q.closed.Load() {
return
}
q.mu.RUnlock()

q.wg.Add(1)
go func() {
Expand All @@ -39,7 +36,5 @@ func (q *Queue) Wait() {
}

func (q *Queue) Close() {
q.mu.Lock()
q.closed = true
q.mu.Unlock()
q.closed.Store(true)
}
Loading