Skip to content
/ chanq Public

Go package provides outgoing queue for channel to use in select case

License

Notifications You must be signed in to change notification settings

powerman/chanq

Repository files navigation

Go package provides outgoing queue for channel to use in select case

Go Reference CI/CD Coverage Status Go Report Card Release

Performance

About 1.5-1.7 times slower than sending to a blocking channel.

Example

out := make(chan []byte) // Usually not buffered, with blocking send.
q := chanq.NewQueue(out)
q.Enqueue([]byte(`one`))
q.Enqueue([]byte(`two`))
for {
    select {
    case data := <-in: // E.g.: forward from in to out without blocking.
        q.Enqueue(data)
    case q.C <- q.Elem: // Works only when queue is not empty.
        q.Dequeue()
    }
}

About

Go package provides outgoing queue for channel to use in select case

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages