repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
354f418
parent
fdadd78
author
Eric Bower
date
2024-09-09 04:31:25 +0000 UTC
fix(pubsub): proper bidirectional blocking
3 files changed,  +23, -5
M go.mod
M go.sum
M go.mod
+1, -1
1@@ -36,7 +36,7 @@ require (
2 	github.com/muesli/termenv v0.15.3-0.20240509142007-81b8f94111d5
3 	github.com/neurosnap/go-exif-remove v0.0.0-20221010134343-50d1e3c35577
4 	github.com/picosh/pobj v0.0.0-20240709135546-27097077b26a
5-	github.com/picosh/pubsub v0.0.0-20240908153701-d8e78982a3da
6+	github.com/picosh/pubsub v0.0.0-20240909042445-92777a8b167b
7 	github.com/picosh/send v0.0.0-20240820031602-5d3b1a4494cc
8 	github.com/picosh/tunkit v0.0.0-20240709033345-8315d4f3cd0e
9 	github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
M go.sum
+2, -2
 1@@ -224,8 +224,8 @@ github.com/picosh/go-rsync-receiver v0.0.0-20240709135253-1daf4b12a9fc h1:bvcsoO
 2 github.com/picosh/go-rsync-receiver v0.0.0-20240709135253-1daf4b12a9fc/go.mod h1:i0iR3W4GSm1PuvVxB9OH32E5jP+CYkVb2NQSe0JCtlo=
 3 github.com/picosh/pobj v0.0.0-20240709135546-27097077b26a h1:Cr1xODiyd/SjjBRtYA9VX6Do3D+w+DansQzkb4NGeyA=
 4 github.com/picosh/pobj v0.0.0-20240709135546-27097077b26a/go.mod h1:VIkR1MZBvxSK2OO47jikxikAO/sKb/vTmXX5ZuYTIvo=
 5-github.com/picosh/pubsub v0.0.0-20240908153701-d8e78982a3da h1:HCu4NyCoexe4Xjm05tWnx8QFxzRXxMoeixDqN6kiZG4=
 6-github.com/picosh/pubsub v0.0.0-20240908153701-d8e78982a3da/go.mod h1:FKC8uot+40iXmuDzTfbxYDG5PIc3ghwkmP2iItBKH0I=
 7+github.com/picosh/pubsub v0.0.0-20240909042445-92777a8b167b h1:/gGhT8y9rnrv8K9ZJKZYzdWvZcnazl8NGE1DGNrD8HU=
 8+github.com/picosh/pubsub v0.0.0-20240909042445-92777a8b167b/go.mod h1:FKC8uot+40iXmuDzTfbxYDG5PIc3ghwkmP2iItBKH0I=
 9 github.com/picosh/send v0.0.0-20240820031602-5d3b1a4494cc h1:IIsJuAFG2ju3cygKVKTIsYYZf21q5S3Dr1H4fGbfgJg=
10 github.com/picosh/send v0.0.0-20240820031602-5d3b1a4494cc/go.mod h1:RAgLDK3LrDK6pNeXtU9tjo28obl5DxShcTUk2nm/KCM=
11 github.com/picosh/senpai v0.0.0-20240503200611-af89e73973b0 h1:pBRIbiCj7K6rGELijb//dYhyCo8A3fvxW5dijrJVtjs=
M pubsub/cli.go
+20, -2
 1@@ -103,6 +103,7 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
 2 
 3 	return func(next ssh.Handler) ssh.Handler {
 4 		return func(sesh ssh.Session) {
 5+			ctx := sesh.Context()
 6 			user, err := getUser(sesh, dbpool)
 7 			if err != nil {
 8 				utils.ErrorHandler(sesh, err)
 9@@ -199,6 +200,14 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
10 					wish.Println(sesh, "no subs found ... waiting")
11 				}
12 
13+				go func() {
14+					<-ctx.Done()
15+					err := pubsub.PubSub.UnPub(msg)
16+					if err != nil {
17+						wish.Errorln(sesh, err)
18+					}
19+				}()
20+
21 				err = pubsub.PubSub.Pub(msg)
22 				wish.Println(sesh, "msg sent!")
23 				if err != nil {
24@@ -217,12 +226,21 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
25 					name = toPublicChannel(channelName)
26 				}
27 
28-				err = pubsub.PubSub.Sub(&psub.Subscriber{
29+				sub := &psub.Subscriber{
30 					ID:     uuid.NewString(),
31 					Name:   name,
32 					Writer: sesh,
33 					Chan:   make(chan error),
34-				})
35+				}
36+
37+				go func() {
38+					<-ctx.Done()
39+					err := pubsub.PubSub.UnSub(sub)
40+					if err != nil {
41+						wish.Errorln(sesh, err)
42+					}
43+				}()
44+				err = pubsub.PubSub.Sub(sub)
45 				if err != nil {
46 					wish.Errorln(sesh, err)
47 				}