observer
This library implements the pub/sub pattern in a generic way. It uses Go's generic types to declare the type of the client identifier as well as the type of the event.
Usage
go get github.com/leonsteinhaeuser/observer
Example
package main
import (
"fmt"
"github.com/leonsteinhaeuser/observer"
)
type Event struct {
ID int
Message string
}
var (
obsrv observer.Observable[int, Event] = observer.NewObserver[int, Event]()
)
func main() {
obsrv.RegisterClient(1, make(chan Event))
obsrv.NotifyAll(Event{
ID: i,
Message: fmt.Sprintf("Message with ID %d", i),
})
fmt.Println("Registered Clients: ", obsrv.Clients())
err := obsrv.DeRegisterClient(1)
if err != nil {
fmt.Println(err)
}
}
If you would like to see a more detailed example, please take a look at the observer example.
Use sync.Map to avoid using constructor NewObserver, minor bugfix
Hi there! The main change is using sync.Map to make Observer structure ready to use without any initialization calls. Also purged uuid dependency in favor of atomic id increment. Last, but not least - fixed potential race condition when trying to write to subscription in goroutine while its channel may be already closed by the cancel func.
Feature/nicer Handle[T]
having used the Handle[T] primitive for some time, I came to conclusion that it's not really necessary to manually unsubscribe from handler using separate function. I's way simpler to let observer close output streams and thus terminate all listeners. If really needed, the context that passed to handlers might be cancelled causing them to return immediately and unsubscribe. By introducing this change, the handler pattern is greatly simplified, see _examples/handler/main.go for illustration.
Please let me know what you think.
[go.mod] bump to v2
Hello again! Please consider putting /v2 into go.mod file, since we're moving on to v2 API. It might be necessary to add v2.0.1 tag that points to that commit, too.
build(deps): bump goreleaser/goreleaser-action from 2 to 3 in /.github/workflows
Bumps goreleaser/goreleaser-action from 2 to 3.
Release notes
Sourced from goreleaser/goreleaser-action's releases.
... (truncated)
Commits
b508e2e
chore: remove workaround for setOutput (#374)0ca84fc
chore(deps): bump yargs from 17.5.1 to 17.6.0 (#373)685a991
chore(deps): bump@actions/core
from 1.9.1 to 1.10.0 (#372)ff11ca2
fix: dist resolution from config file (#369)ef54bd4
chore(deps): bump@actions/core
from 1.8.2 to 1.9.1 (#367)aab65f3
chore(deps): bump@actions/core
from 1.6.0 to 1.8.2 (#358)7bb9301
chore(deps): bump ghaction-import-gpg to v5 (#359)50f10b3
chore(deps): bump crazy-max/ghaction-import-gpg from 4 to 5 (#360)188063d
ci: fix workflow (#357)7e270cc
docs: bump actions to latest major (#356)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)build(deps): bump codecov/codecov-action from 2 to 3 in /.github/workflows
Bumps codecov/codecov-action from 2 to 3.
Release notes
Sourced from codecov/codecov-action's releases.
... (truncated)
Changelog
Sourced from codecov/codecov-action's changelog.
... (truncated)
Commits
d9f34f8
release: update changelog and version to 3.1.1 (#828)0e9e7b4
Plumb failCi into verification function. (#769)7f20bd4
build(deps): bump@actions/core
from 1.8.2 to 1.9.1 (#798)13bc253
build(deps): bump openpgp from 5.3.0 to 5.4.0 (#799)5c0da1b
Trim arguments after splitting them (#791)68d5f6d
Fixnetwork
entry in table (#783)2a829b9
Switch to v3 (#774)8e09eaf
build(deps-dev): bump typescript from 4.7.3 to 4.7.4 (#766)39e2229
build(deps): bump actions/upload-artifact from 2.3.1 to 3.1.0 (#748)b2b7703
build(deps): bump openpgp from 5.2.1 to 5.3.0 (#760)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)build(deps): bump TimonVS/pr-labeler-action from 3 to 4 in /.github/workflows
Bumps TimonVS/pr-labeler-action from 3 to 4.
Release notes
Sourced from TimonVS/pr-labeler-action's releases.
Commits
8b99f40
Compile dist01938b9
Merge pull request #75 from TimonVS/feat/repo-token-config17041f9
Allow repo token to be passed inwith
sectionaeec1bb
Upgrade to latest version of action9d99f19
Merge pull request #72 from TimonVS/main-licensese2a2c89
Update action version in READMEad46b65
Merge pull request #59 from danyeaw/patch-18a69b8c
Add contents permission to job permissionsb7e7b3e
Upgrade js-yaml dependencyadbeb0d
Upgrade matcher libraryDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)enhancement: minor ci improvements
Description
This PR changes a few CI settings. It allows us to run regular dependabot checks for Go as well as GitHub actions, it automatically flags issues based on
feature
,enhancement
,fix
ordocumentation
prefixes.Checklist
build(deps): bump goreleaser/goreleaser-action from 3 to 4 in /.github/workflows
Bumps goreleaser/goreleaser-action from 3 to 4.
Release notes
Sourced from goreleaser/goreleaser-action's releases.
Commits
8f67e59
chore: regenerate78df308
chore(deps): bump minimatch from 3.0.4 to 3.1.2 (#383)66134d9
Merge remote-tracking branch 'origin/master' into flarco/master3c08cfd
chore(deps): bump yargs from 17.6.0 to 17.6.25dc579b
docs: add example when using workdir along with upload-artifact (#366)3b7d1ba
feat!: remove auto-snapshot on dirty tag (#382)23e0ed5
fix: do not override GORELEASER_CURRENT_TAG (#370)1315dab
update buildb60ea88
improve install4d25ab4
Update goreleaser.tsDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)