Skip to content
This repository was archived by the owner on Jun 17, 2019. It is now read-only.

damnever/goqueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A GoRoutine safe queue for Golang Build Status GoDoc

It is similar to the Queue of Python.

Installation

go get github.com/damnever/goqueue

Example

Just for example, I use Queue.Get(0) and Queue.PutNoWait(value) more and often, but channel is not a right way do that...

package main

import (
    "fmt"
    "sync"

    "github.com/Damnever/goqueue"
)

func main() {
    queue := goqueue.New(0)
    wg := &sync.WaitGroup{}

    worker := func(queue *goqueue.Queue) {
        defer wg.Done()
        for !queue.IsEmpty() {
            val, err := queue.Get(0)
            if err != nil {
                fmt.Println("Unexpect Error: %v\n", err)
            }
            num := val.(int)
            fmt.Printf("-> %v\n", num)
            if num%3 == 0 {
                for i := num + 1; i < num+3; i++ {
                    queue.PutNoWait(i)
                }
            }
        }
    }

    go func() {
        defer wg.Done()
        for i := 0; i <= 27; i += 3 {
            queue.PutNoWait(i)
        }
    }()

    for i := 0; i < 5; i++ {
        go worker(queue)
    }

    wg.Add(6)
    wg.Wait()

    fmt.Println("All task done!!!")
}

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy