Skip to content

srishina/delayq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

delayq

Delayed queue in golang

An example

package main

import (
	"fmt"
	"time"

	"github.com/srishina/delayq"
)

const (
	delayDuration = 4 * time.Second
)

func main() {
	delayedq := delayq.NewDelayQueue(12)
	defer delayedq.Close()

	testItem := "Hello world!"
	// place an item into the queue with the delay duration
	delayedq.Put(testItem, delayDuration)

	// the input items are delayed
	done := make(chan struct{})
	go func() {
		defer close(done)
		item, _ := delayedq.Get()
		fmt.Println("Delayed item received, value: ", item)
	}()

	fmt.Println("Wait till the delayed item is received...")

	select {
	case <-time.After(delayDuration + time.Second):
		fmt.Println("error: shoud not timeout")
	case <-done:
		fmt.Println("Finished...")
	}
}

LICENSE

MIT

About

Delayed queue in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages