github.com/koko1123/flow-go-1@v0.29.6/module/mempool/queue/heroStore.go (about) 1 package queue 2 3 import ( 4 "github.com/rs/zerolog" 5 6 "github.com/koko1123/flow-go-1/engine" 7 "github.com/koko1123/flow-go-1/module" 8 "github.com/koko1123/flow-go-1/module/mempool/queue/internal" 9 ) 10 11 // HeroStore is a FIFO (first-in-first-out) size-bound queue for maintaining engine.Message types. 12 // It is based on HeroQueue. 13 type HeroStore struct { 14 q *HeroQueue 15 } 16 17 func NewHeroStore(sizeLimit uint32, logger zerolog.Logger, collector module.HeroCacheMetrics) *HeroStore { 18 return &HeroStore{ 19 q: NewHeroQueue(sizeLimit, logger, collector), 20 } 21 } 22 23 // Put enqueues the message into the message store. 24 // 25 // Boolean returned variable determines whether enqueuing was successful, i.e., 26 // put may be dropped if queue is full or already exists. 27 func (c *HeroStore) Put(message *engine.Message) bool { 28 return c.q.Push(internal.NewMessageEntity(message)) 29 } 30 31 // Get pops the queue, i.e., it returns the head of queue, and updates the head to the next element. 32 // Boolean return value determines whether pop is successful, i.e., popping an empty queue returns false. 33 func (c *HeroStore) Get() (*engine.Message, bool) { 34 head, ok := c.q.Pop() 35 if !ok { 36 return nil, false 37 } 38 39 msg := head.(internal.MessageEntity).Msg 40 return &msg, true 41 }