Skip to content

lcd1232/dqueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Report Card Build Status Coverage Godoc Releases LICENSE

dqueue

Queue with delayed items

Installation

go get github.com/lcd1232/dqueue

Usage

package main
import (
    "context"
    "fmt"
    "time"

    "github.com/lcd1232/dqueue"
)

func main() {
    q := dqueue.NewQueue()
    defer q.Stop(context.Background())
    // Insert "some value" with delay 1 hour 
    q.Insert("some value", time.Hour)
    q.Insert(2, time.Minute)
    v, ok := q.Pop()
    fmt.Println(v, ok) // Prints <nil> false
    // Due to golang timer implementation it can take a little more time 
    time.Sleep(time.Minute+time.Second) 
    v, ok = q.Pop()
    fmt.Println(v, ok) // Prints 2 true

    // Use context cancellation
    ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
    defer cancel()
    v, ok = q.PopCtx(ctx)
    fmt.Println(v, ok) // Prints <nil> false
    
    // Get value from channel
    select {
    case v = <- q.Channel():
    fmt.Println(v, ok) // Prints some value false
    }
}

Project versioning

dqueue uses semantic versioning. API should not change between patch and minor releases. New minor versions may add additional features to the API.

Licensing

"The code in this project is licensed under MIT license."

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages