github.com/MeteorsLiu/simpleMQ@v1.0.3/queue/fq.go (about)

     1  package queue
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/MeteorsLiu/simpleMQ/generic"
     7  )
     8  
     9  type FairQueue struct {
    10  	sync.RWMutex
    11  	cap   int
    12  	queue *generic.List[Task]
    13  }
    14  
    15  func WithFairQueueCap(cap int) Options {
    16  	return func(queue Queue) {
    17  		queue.Resize(cap)
    18  	}
    19  }
    20  
    21  func NewFairQueue(opts ...Options) Queue {
    22  	fq := &FairQueue{
    23  		queue: generic.New[Task](),
    24  	}
    25  	for _, o := range opts {
    26  		o(fq)
    27  	}
    28  
    29  	return fq
    30  }
    31  
    32  func (f *FairQueue) Resize(cap int) bool {
    33  	return true
    34  }
    35  
    36  func (f *FairQueue) Cap() int {
    37  	f.RLock()
    38  	defer f.RUnlock()
    39  	return f.cap
    40  }
    41  func (f *FairQueue) Len() int {
    42  	f.RLock()
    43  	defer f.RUnlock()
    44  	return f.cap
    45  }
    46  
    47  func (f *FairQueue) Free() int {
    48  	f.RLock()
    49  	defer f.RUnlock()
    50  	return f.cap
    51  }
    52  
    53  func (f *FairQueue) IsClosed() bool {
    54  	return false
    55  }
    56  
    57  // close wait until all tasks are executed.
    58  func (f *FairQueue) Close() {
    59  
    60  }
    61  
    62  func (f *FairQueue) Publish(t Task) bool {
    63  	return false
    64  }
    65  
    66  func (f *FairQueue) ForcePublish(t Task) error {
    67  	return nil
    68  }
    69  func (f *FairQueue) Subscribe() (chan Task, error) {
    70  	return nil, nil
    71  }
    72  func (f *FairQueue) TryPop() (Task, bool) {
    73  	return nil, false
    74  }
    75  
    76  func (f *FairQueue) Pop() (Task, error) {
    77  	return nil, nil
    78  }
    79  
    80  func (f *FairQueue) Copy() []Task {
    81  	return nil
    82  }
    83  
    84  func (f *FairQueue) Save(_ func(Task)) {
    85  
    86  }