oleiade/lane

Strange queue behaviour

sashabaranov opened this issue · 3 comments

I tried this code sample based on README:

package main

import "fmt"
import "github.com/oleiade/lane"
import "runtime"


func main() {
    // runtime.GOMAXPROCS(3)

    queue := lane.NewQueue()
    queue.Enqueue("grumpyClient")
    queue.Enqueue("happyClient")
    queue.Enqueue("ecstaticClient")


    // Let's handle the clients asynchronously
    for client := queue.Dequeue(); client != nil; {
        go fmt.Println(client)
    }
}

What I expected from it: should print 3 strings from queue and exit.
What actually happens: prints "grumpyClient" lots of times. Removing "go" in loop does not change anything.

Tested on go1.4.1 darwin/amd64(os x 10.9.5) and go1.2.1 linux/amd64(ubuntu precise). Same thing

Uncommenting line with runtime.GOMAXPROCS(3) causes lots of tracebacks on OS X(not on linux).

I have some behaviour go version go1.4 windows/386

Library is fine, the problem was in code sample.

Thanks for the PR @sashabaranov