https://github.com/bobvawter/go-notify
Golang variables with channel-based change notifications
https://github.com/bobvawter/go-notify
apache2-license go golang
Last synced: 3 months ago
JSON representation
Golang variables with channel-based change notifications
- Host: GitHub
- URL: https://github.com/bobvawter/go-notify
- Owner: bobvawter
- License: apache-2.0
- Created: 2025-01-08T22:27:25.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-01-08T22:59:44.000Z (4 months ago)
- Last Synced: 2025-01-08T23:58:46.925Z (4 months ago)
- Topics: apache2-license, go, golang
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Golang Channel-Based Data Notifications
[](https://pkg.go.dev/vawter.tech/notify)
```shell
go get vawter.tech/notify
```This package provides a storage variable type with channel-based notifications of changes.
It is useful for values that need to be observed at runtime, such as configuration types.
The `notify.Var` type can be thought of as a cross between an `atomic.Value` coupled to
a `sync.Cond`, albeit using channels for control-flow composition.```go
v := notify.VarOf(&ConfigurationType{})// Somewhere in your run loop to respond to changes.
for cfg, cfgUpdated := v.Get(); ; {
// Do something with the new configuration.
select {
case <-cfgUpdated:
// The channel will be closed when the contents of the
// variable have changed. This composes easily with multiple
// channels.
cfg, cfgUpdated = v.Get()case <-ctx.Done():
return
}
}// Elsewhere to update the value.
v.Set(&Configuration{Updated: true})
```## Project History
This repository was extracted from `github.com/cockroachdb/field-eng-powertools` using the command
`git filter-repo --path stopvar --subdirectory-filter notify --path LICENSE` by the code's original author.