Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
leodeim authored Jul 28, 2023
1 parent 67ba52b commit 7d9cab1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,36 @@ For more examples check out `examples/` folder.

## Change notifications

### Callback
### Callbacks

Register a callback function, which will be called on config change in non blocking way:
```go
c.AddCallback(func(cfg ConfigType) {
id := c.AddCallback(func(cfg ConfigType) {
// handle config update
})
```
Callback could be removed by `id`:
```go
c.RemoveCallback(id)
```

### Subscribers

You can register another type of callback - **subscriber**. It will be called on config change and will wait for it to complete.
It has different signature than callback: it can return an error and in case subscriber callback returns an error - whole config update is being rolled back.
Example:
```go
c.AddSubscriber(func(cfg ConfigType) error {
id := c.AddSubscriber(func(cfg ConfigType) error {
if err := tryConfigUpdate(cfg); err != nil {
return err
}
return nil
})
```
Subscriber could be removed dynamically:
```go
c.RemoveSubscriber(id)
```

## File handler

Expand Down

0 comments on commit 7d9cab1

Please sign in to comment.