nbc

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2015 License: MIT Imports: 2 Imported by: 17

README

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
}

Documentation

Overview

Non-blocking channel for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NonBlockingChan

type NonBlockingChan struct {
	Send chan<- interface{}
	Recv <-chan interface{}
	// contains filtered or unexported fields
}

Special type that mimics the behavior of a channel but does not block when items are sent. Items are stored internally until received. Closing the Send channel will cause the Recv channel to be closed after all items have been received.

func New

func New() *NonBlockingChan

Create a new non-blocking channel.

func (*NonBlockingChan) Len

func (n *NonBlockingChan) Len() int

Retrieve the number of items waiting to be received.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL