https://github.com/b1nary-gr0up/phos
Channel with internal handlers and diversified options.
https://github.com/b1nary-gr0up/phos
channel go
Last synced: 7 months ago
JSON representation
Channel with internal handlers and diversified options.
- Host: GitHub
- URL: https://github.com/b1nary-gr0up/phos
- Owner: B1NARY-GR0UP
- License: apache-2.0
- Created: 2023-03-23T17:31:23.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-13T05:18:44.000Z (over 1 year ago)
- Last Synced: 2025-03-24T03:23:40.197Z (7 months ago)
- Topics: channel, go
- Language: Go
- Homepage:
- Size: 157 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

PHOS is a channel with internal handlers and diversified options.
[](https://goreportcard.com/report/github.com/B1NARY-GR0UP/phos)
## Install
```shell
go get github.com/B1NARY-GR0UP/phos
```
## Quick Start
```go
package main
import (
"context"
"fmt"
"github.com/B1NARY-GR0UP/phos"
)
func hello(_ context.Context, data string) (string, error) {
return data + " by ", nil
}
func world(_ context.Context, data string) (string, error) {
return data + "BINARY", nil
}
func main() {
ph := phos.New[string]()
defer ph.Close()
ph.Append(hello, world)
ph.In <- "PHOS"
res := <-ph.Out
ph.Delete(ph.Len() - 2)
fmt.Println(res.Data) // PHOS by BINARY
}
```
## Configuration
| Option | Default | Description | Example |
|----------------------|------------------------|--------------------------------------------------------------------------------------|-------------------------|
| `WithContext` | `context.Background()` | Set context for PHOS | [example](phos_test.go) |
| `WithZero` | `false` | Set zero value for return when error happened | [example](phos_test.go) |
| `WithTimeout` | `3 * time.Second` | Set timeout for handlers execution | [example](phos_test.go) |
| `WithErrHandleFunc` | `nil` | Set error handle function for PHOS which will be called when handle error happened | [example](phos_test.go) |
| `WithErrTimeoutFunc` | `nil` | Set error timeout function for PHOS which will be called when timeout error happened | [example](phos_test.go) |
| `WithErrDoneFunc` | `nil` | Set err done function for PHOS which will be called when context done happened | [example](phos_test.go) |
## Blogs
- [PHOS: A Go channel extension with internal handlers](https://dev.to/justlorain/phos-a-go-channel-extension-with-internal-handlers-4lad) | [中文](https://juejin.cn/post/7216236114981584953)
## License
PHOS is distributed under the [Apache License 2.0](./LICENSE). The licenses of third party dependencies of PHOS are explained [here](./licenses).
## ECOLOGY
PHOS is a Subproject of the Basic Middleware Service