https://github.com/x1unix/chanspy
The easiest way to check if Go channel is closed
https://github.com/x1unix/chanspy
channels golang golang-package
Last synced: about 1 month ago
JSON representation
The easiest way to check if Go channel is closed
- Host: GitHub
- URL: https://github.com/x1unix/chanspy
- Owner: x1unix
- License: mit
- Created: 2024-03-23T20:59:33.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-03-24T07:56:23.000Z (about 1 year ago)
- Last Synced: 2025-01-31T07:16:10.027Z (3 months ago)
- Topics: channels, golang, golang-package
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chanspy
> Go Channel Spy
[](https://goreportcard.com/report/github.com/x1unix/chanspy)
[](https://pkg.go.dev/github.com/x1unix/chanspy)This module contains helpers for Go channel types like:
* Checking if channel is closed without read.
* Obtaining channel length and capacity.
* etc.## Disclaimer
This package (ab)uses unsafe techniques, use with caution.
> I'm not responsible for broken deployments, segfaults, thermonuclear war, or you getting fired because undefined behavior in the code led to a company going bankrupt.
> Please do some research if you have any concerns about features included in this package before using it!
> YOU are choosing to make these modifications, and if you point the finger at me for messing up your program, I will laugh at you.## Usage
```go
package mainimport (
"fmt""github.com/x1unix/chanspy"
)func main() {
// This is a fast way to check if channel is closed without block.
// Use chanspy.ValueOf(ch, chanspy.WithLock) for thread-safe way.
ch := make(chan int)
fmt.Println(chanspy.IsClosed(ch)) // Prints: falseclose(ch)
fmt.Println(chanspy.IsClosed(ch)) // Prints: true
}
```See [examples](./example_test.go) for more details.