A Flip Queue implementation in Golang.
Flip queue is a lock less producer consumer queue that allows the producer and consumer concurrently use the same queue without any synchronization. It allows better performance in use cases where data published continuously and collected rapidly
Flip queue maintains two separate queue for producer and consumer. As per the requirement of consumption of data it flips the queue.
Flip : A phenomena where queue changes its role. That is the producer queue becomes consumer queue and vice versa.
gofqueue provides basic functionality of a queue. i.e Create, Insert and Get.
import "github.com/swarvanusg/gofqueue"Createfqueue() takes the max length of the queue. For making the dynamic length 0 should be specified
fqeueu := gofqueue.Createfqueue(<length>)Insert takes one param of type interface{} to accept any type of object
err := fqueue.Insert(<value>)Get returns the first-most added data
data, err := fqueue.Get()Getall returns all the data as per the FIFO order. In concurrent queueing it tries to get as max added data, which sometimes make the call blocking if you have a nonstop producer
data, err := fqueue.Getall()A publisher could be very useful to dump data of the queue after a regular interval. It uses Publish interface type to call a publish() with all data after a specified interval. If 0 is specified the interval is set to default 1 sec. If queue is empty, call to publish() after the interval is ignored. Publisher doesn't carry out any locking, user should not make any explicit call to retrive data, or launch multiple publisher.
fqueue.Startpublish(<interval>, publisher)A publiser need to be stopped explicitly by calling Stoppublish(). After stopping publisher could be re launched again
fqueue.Stoppublish()It is only supported in single consumer and single producer model. In order to use same queue in multiple consumer and producer concurrently, explicit locking should be handled.