Skip to content

hectane/go-nonblockingchan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-nonblockingchan

Build Status GoDoc MIT License

A special type that mimics the behavior of a channel but does not block when items are sent.

Features

  • Send items without ever worrying that the send will block
  • Check how many items are waiting to be received
  • Synchronized access to members - use it from any goroutine

Usage

To use the package, add the following import:

import "github.com/hectane/go-nonblockingchan"

Use the New() function to create a new instance:

c := nbc.New()

To send an item on the channel, use the Send field:

c.Send <- true

Sending will always succeed immediately. The item will be added to an internal buffer until it is received:

v, ok := <-c.Recv
if ok {
    // value was received
} else {
    // channel was closed
}

About

Non-blocking channel for Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages