https://github.com/sergeyfrolov/bsbuffer
BSBuffer: B - Blocking - Read() calls are blocking. S - Safe - Supports arbitrary amount of readers and writers. Could be unblocked and turned into SBuffer. "Smart data structures and dumb code works a lot better than the other way around."(c)
https://github.com/sergeyfrolov/bsbuffer
blocking buffer concurrent-buffer goroutine-safe safe
Last synced: about 1 month ago
JSON representation
BSBuffer: B - Blocking - Read() calls are blocking. S - Safe - Supports arbitrary amount of readers and writers. Could be unblocked and turned into SBuffer. "Smart data structures and dumb code works a lot better than the other way around."(c)
- Host: GitHub
- URL: https://github.com/sergeyfrolov/bsbuffer
- Owner: sergeyfrolov
- License: lgpl-3.0
- Created: 2017-05-11T11:12:11.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-03T21:39:50.000Z (almost 7 years ago)
- Last Synced: 2025-04-08T20:14:47.389Z (2 months ago)
- Topics: blocking, buffer, concurrent-buffer, goroutine-safe, safe
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bsbuffer
`import "github.com/SergeyFrolov/bsbuffer"`* [Overview](#pkg-overview)
* [Imported Packages](#pkg-imports)
* [Index](#pkg-index)## Overview
No packages beyond the Go standard library are imported.
## Index
* [type BSBuffer](#BSBuffer)
* [func NewBSBuffer() \*BSBuffer](#NewBSBuffer)
* [func (b \*BSBuffer) Read(p []byte) (n int, err error)](#BSBuffer.Read)
* [func (b \*BSBuffer) Unblock()](#BSBuffer.Unblock)
* [func (b \*BSBuffer) Write(p []byte) (n int, err error)](#BSBuffer.Write)#### Package files
[bsbuffer.go](./bsbuffer.go)## type [BSBuffer](./bsbuffer.go#L17-L29)
``` go
type BSBuffer struct {
sync.Mutex
// contains filtered or unexported fields
}
```
BSBuffer:
B - Blocking - Read() calls are blocking.
S - Safe - Supports arbitrary amount of readers and writers.
Could be unblocked and turned into SBuffer.### func [NewBSBuffer](./bsbuffer.go#L32)
``` go
func NewBSBuffer() *BSBuffer
```
Creates new BSBuffer### func (\*BSBuffer) [Read](./bsbuffer.go#L63)
``` go
func (b *BSBuffer) Read(p []byte) (n int, err error)
```
Reads data from the BSBuffer, blocking until a writer arrives or the BSBuffer is unblocked.
If the write end is closed with an error, that error is returned as err; otherwise err is EOF.
Supports multiple concurrent goroutines and p is valid forever.### func (\*BSBuffer) [Unblock](./bsbuffer.go#L108)
``` go
func (b *BSBuffer) Unblock()
```
Turns BSBuffer into SBuffer: Read() is no longer blocking, but still safe.
Unblock() is safe to call multiple times.### func (\*BSBuffer) [Write](./bsbuffer.go#L85)
``` go
func (b *BSBuffer) Write(p []byte) (n int, err error)
```
Non-blocking write appends the contents of p to the buffer, growing the buffer as needed.
The return value n is the length of p; err is always nil.
If the buffer becomes too large, Write will panic with ErrTooLarge.
Supports multiple concurrent goroutines and p is safe for reuse right away.- - -
Generated by [godoc2ghmd](https://github.com/GandalfUK/godoc2ghmd)