Ejemplo n.º 1
0
// NewTimedExiryPool creates a ...NewTimedExiryPool
func NewTimedExiryPool(expiryTimeInMilli uint64) *ExpiringObjectPool {
	tep := &ExpiringObjectPool{LinkedList: list.New(), ExpiryPeriod: expiryTimeInMilli, Sem: semaphore.New()}
	go tep.removeExpiredItems()
	return tep
}
Ejemplo n.º 2
0
	// PublisherCount is the amount of publisher goroutines we want to run
	PublisherCount = 25

	// MinSleepDurationMilli is used to generate a random sleep interval for publishers (so we can see things out or order)
	MinSleepDurationMilli = 0

	// MaxSleepDurationMilli is used to generate a random sleep interval for publishers (so we can see things out or order)
	MaxSleepDurationMilli = 30
)

var (
	// SyncMutex is used to synchronise/lock the publish/Consume queue
	SyncMutex = sync.Mutex{}

	// CountingSem is our semaphore used to wait for published items
	CountingSem = semaphore.New()

	// PubsubQueue is our publisher/consumer queue where items are added and consumed from
	PubsubQueue = list.New()

	// ConsumeCount is the total amount of items that have been consumed (so we know when to end the example)
	ConsumeCount = 0

	// WaitChan is used to pause the main routine until we're done
	WaitChan = make(chan bool)
)

// main - entry point
func main() {
	// Run our consumer routines - they'll wait until something has been published
	for i := 0; i < ConsumerCount; i++ {