Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hectane/go-nonblockingchan
Non-blocking channel for Go
https://github.com/hectane/go-nonblockingchan
golang
Last synced: about 1 month ago
JSON representation
Non-blocking channel for Go
- Host: GitHub
- URL: https://github.com/hectane/go-nonblockingchan
- Owner: hectane
- License: mit
- Created: 2015-11-05T00:03:55.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-05T02:00:33.000Z (almost 9 years ago)
- Last Synced: 2024-06-18T20:24:46.114Z (3 months ago)
- Topics: golang
- Language: Go
- Size: 125 KB
- Stars: 31
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## go-nonblockingchan
[![Build Status](https://travis-ci.org/hectane/go-nonblockingchan.svg?branch=master)](https://travis-ci.org/hectane/go-nonblockingchan)
[![GoDoc](https://godoc.org/github.com/hectane/go-nonblockingchan?status.svg)](https://godoc.org/github.com/hectane/go-nonblockingchan)
[![MIT License](http://img.shields.io/badge/license-MIT-9370d8.svg?style=flat)](http://opensource.org/licenses/MIT)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
}