cch is a simple wrapper over chan interface{}
to allow multiple writers/readers with safe closing without panicing.
go get github.com/OneOfOne/cch
-
Because quite often I need to have multiple writers and readers.
-
I had a proposal to allow a safe'ish send-on-a-closed channel using select, however it got rejected.
- The only overhead is a mutex.RLock on Send/Recv.
- It adds complexity to the client code.
- Slight overhead and memory overhead because of the complexity
import (
"github.com/OneOfOne/cch"
)
const NumWorkers = 100
func main() {
ch := cch.NewBuffered(NumWorkers)
for i := 0; i < NumWorkers; i++ {
go worker(ch)
}
for i := 0; i < NumManagers; i++ {
go manager(ch)
}
// wait for some condition
ch.Close()
}
- Better documentation.
- More tests.
- Better select/multi-impl.
- Support
context.Context
.
Apache v2.0 (see LICENSE file).
Copyright 2016-2017 Ahmed <OneOfOne> W.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.