dqueue

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 4 Imported by: 0

README

go-dqueue

test Go Reference Go Report Card codecov

dqueue provides high performance delay queue with unlimited buffer in Go.

Usage

Try it on The Go Playground.

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/morikuni/go-dqueue"
)

func Example() {
	queue := dqueue.New()
	queue.Push("hello", dqueue.Delay(time.Second))
	fmt.Println(time.Now())
	fmt.Println(queue.Pull(context.Background()))
	fmt.Println(time.Now())
	// Output:
	// 2009-11-10 23:00:00 +0000 UTC m=+0.000000001
	// hello <nil>
	// 2009-11-10 23:00:01 +0000 UTC m=+1.000000001
}

queue.Pull blocks until any item become available after the delay.

Performance

pkg: github.com/morikuni/go-dqueue
BenchmarkQueue_Push          55974181      232 ns/op    125 B/op    2 allocs/op
BenchmarkQueue_Pull          21256920      700 ns/op      0 B/op    0 allocs/op
BenchmarkQueue_PushPull      27615370      436 ns/op     80 B/op    2 allocs/op

1,000,000+ ops/sec.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PushOption

type PushOption interface {
	// contains filtered or unexported methods
}

func Delay

func Delay(d time.Duration) PushOption

func DelayUntil

func DelayUntil(t time.Time) PushOption

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func New

func New() *Queue

func (*Queue) Flush

func (q *Queue) Flush() []interface{}

func (*Queue) Pull

func (q *Queue) Pull(ctx context.Context) (interface{}, error)

func (*Queue) Push

func (q *Queue) Push(v interface{}, opts ...PushOption)

Jump to

Keyboard shortcuts

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