deliveryqueue

command module
v0.0.0-...-58614dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 4 Imported by: 0

README

DeliveryQueue

Go Report Card

DeliveryQueue is a queue with embedded rate limiter that guarantees that delivery function will not be triggered more than specified number of times per second.

go get -u github.com/bazuker/deliveryQueue

Example

const (
	MaxMessagesPerSecond = 30
	MessagesToDeliver = 120
)

func main() {
	wg := &sync.WaitGroup{}

	dq, _ := queue.NewDeliveryQueue(MaxMessagesPerSecond, func(item interface{}) {
		log.Println(item)
		wg.Done()
	})

	go dq.Poll()

	for i := 1; i <= MessagesToDeliver; i++ {
		dq.Add(i)
	}

	wg.Add(MessagesToDeliver)

	log.Println("All messages are submitted")

	start := time.Now()
	wg.Wait()
	log.Printf("Delivered %d messages in %f seconds", MessagesToDeliver, time.Now().Sub(start).Seconds())
}
2019/07/13 17:25:57 All messages are submitted
2019/07/13 17:25:57 1
2019/07/13 17:25:57 2
...
2019/07/13 17:26:01 119
2019/07/13 17:26:01 120
2019/07/13 17:26:01 Delivered 120 messages in 4.148081 seconds

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
buffer
Spin provides objects for assisting with sleeping while waiting for an action to become available.
Spin provides objects for assisting with sleeping while waiting for an action to become available.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL