Skip to content
/ queue Public

Lightweight, thread-safe, blocking FIFO queue based on auto-resizing circular buffer

Notifications You must be signed in to change notification settings

sheerun/queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Queue

GoDoc Release Software License

Lightweight, tested, performant, thread-safe, blocking FIFO queue based on auto-resizing circular buffer.

Usage

package main

import (
  "fmt"
  "sync"
  "time"

  "github.com/sheerun/queue"
)

func main() {
  q := queue.New()
  var wg sync.WaitGroup
  wg.Add(2)

  // Worker 1
  go func() {
    for i := 0; i < 500; i++ {
      item := q.Pop()
      fmt.Printf("%v\n", item)
      time.Sleep(10 * time.Millisecond)
    }
    wg.Done()
  }()

  // Worker 2
  go func() {
    for i := 0; i < 500; i++ {
      item := q.Pop()
      fmt.Printf("%v\n", item)
      time.Sleep(10 * time.Millisecond)
    }
    wg.Done()
  }()

  for i := 0; i < 1000; i++ {
    q.Append(i)
  }

  wg.Wait()
}

License

MIT

About

Lightweight, thread-safe, blocking FIFO queue based on auto-resizing circular buffer

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages