pico / feat(pubsub): pub new flag, `-t {duration}` timeout #27

open · opened on 2024-09-24T01:51:53Z by erockmKua
Help
# add changes to patch request
git format-patch main --stdout | ssh pr.pico.sh pr add 27
# add review to patch request
git format-patch main --stdout | ssh pr.pico.sh pr add --review 27
# remove patchset
ssh pr.pico.sh ps rm ps-x
# checkout all patches
ssh pr.pico.sh pr print 27 | git am -3
# print a diff between the last two patches in a patch request
ssh pr.pico.sh pr diff 27
# accept PR
ssh pr.pico.sh pr accept 27
# close PR
ssh pr.pico.sh pr close 27

Logs

erockmKua created pr with ps-44 on 2024-09-24T01:51:53Z
erockmKua added ps-45 on 2024-09-24T02:05:30Z
erockmKua added ps-46 on 2024-09-24T02:06:53Z

Patchsets

Diff ↕
The default is no timeout.
 pubsub/cli.go | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
 1From c3f5de386adacb891c8562feb8e4f51c969a53a3 Mon Sep 17 00:00:00 2001
 2From: Eric Bower <me@erock.io>
 3Date: Mon, 23 Sep 2024 21:50:37 -0400
 4Subject: [PATCH] feat(pubsub): pub new flag, `-t {duration}` timeout
 5
 6The default is no timeout.
 7---
 8 pubsub/cli.go | 27 ++++++++++++++++++++++++++-
 9 1 file changed, 26 insertions(+), 1 deletion(-)
10
11diff --git a/pubsub/cli.go b/pubsub/cli.go
12index a0d8121..3eac378 100644
13--- a/pubsub/cli.go
14+++ b/pubsub/cli.go
15@@ -8,6 +8,7 @@ import (
16 	"log/slog"
17 	"strings"
18 	"text/tabwriter"
19+	"time"
20 
21 	"github.com/charmbracelet/ssh"
22 	"github.com/charmbracelet/wish"
23@@ -181,6 +182,7 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
24 				pubCmd := flagSet("pub", sesh)
25 				empty := pubCmd.Bool("e", false, "Send an empty message to subs")
26 				public := pubCmd.Bool("p", false, "Anyone can sub to this channel")
27+				timeout := pubCmd.String("t", "", "Timeout as a Go duration before cancelling the pub event. Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'. Default is no timeout.")
28 				if !flagCheck(pubCmd, repoName, cmdArgs) {
29 					return
30 				}
31@@ -215,8 +217,20 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
32 					})
33 				}
34 
35+				tt := *timeout
36+				wait := time.Duration(0)
37+				str := "no subs found ... waiting"
38+				if tt != "" {
39+					wait, err = time.ParseDuration(*timeout)
40+					if err != nil {
41+						wish.Errorln(sesh, err)
42+						return
43+					}
44+					str += " " + wait.String()
45+				}
46+
47 				if count == 0 {
48-					wish.Println(sesh, "no subs found ... waiting")
49+					wish.Println(sesh, str)
50 				}
51 
52 				go func() {
53@@ -224,6 +238,17 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
54 					pub.Cleanup()
55 				}()
56 
57+				go func() {
58+					// never cancel pub event
59+					if tt == "" {
60+						return
61+					}
62+
63+					time.Sleep(wait)
64+					pub.Cleanup()
65+					sesh.Close()
66+				}()
67+
68 				err = pubsub.PubSub.Pub(name, pub)
69 				wish.Println(sesh, "msg sent!")
70 				if err != nil {
71
72base-commit: d155314b1c22325ee1ce2aedaefd3f90b2770a7b
73-- 
742.45.2
75
ps-44 by erockmKua on 2024-09-24T01:51:53Z
Diff ↕
No patches found, that doesn't seem right.
ps-45 by erockmKua on 2024-09-24T02:05:30Z
Diff ↕
 pubsub/cli.go | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
 1From a3ed6362310a516dacfa93bee7b38d1dd7214798 Mon Sep 17 00:00:00 2001
 2From: Eric Bower <me@erock.io>
 3Date: Mon, 23 Sep 2024 22:06:24 -0400
 4Subject: [PATCH 2/2] refactor(pubsub): use flags built-in Duration
 5
 6---
 7 pubsub/cli.go | 16 +++++-----------
 8 1 file changed, 5 insertions(+), 11 deletions(-)
 9
10diff --git a/pubsub/cli.go b/pubsub/cli.go
11index 3eac378..8d4d851 100644
12--- a/pubsub/cli.go
13+++ b/pubsub/cli.go
14@@ -182,7 +182,7 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
15 				pubCmd := flagSet("pub", sesh)
16 				empty := pubCmd.Bool("e", false, "Send an empty message to subs")
17 				public := pubCmd.Bool("p", false, "Anyone can sub to this channel")
18-				timeout := pubCmd.String("t", "", "Timeout as a Go duration before cancelling the pub event. Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'. Default is no timeout.")
19+				timeout := pubCmd.Duration("t", -1, "Timeout as a Go duration before cancelling the pub event. Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'. Default is no timeout.")
20 				if !flagCheck(pubCmd, repoName, cmdArgs) {
21 					return
22 				}
23@@ -218,15 +218,9 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
24 				}
25 
26 				tt := *timeout
27-				wait := time.Duration(0)
28 				str := "no subs found ... waiting"
29-				if tt != "" {
30-					wait, err = time.ParseDuration(*timeout)
31-					if err != nil {
32-						wish.Errorln(sesh, err)
33-						return
34-					}
35-					str += " " + wait.String()
36+				if tt > 0 {
37+					str += " " + tt.String()
38 				}
39 
40 				if count == 0 {
41@@ -240,11 +234,11 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
42 
43 				go func() {
44 					// never cancel pub event
45-					if tt == "" {
46+					if tt == -1 {
47 						return
48 					}
49 
50-					time.Sleep(wait)
51+					<-time.After(tt)
52 					pub.Cleanup()
53 					sesh.Close()
54 				}()
55-- 
562.45.2
57
ps-46 by erockmKua on 2024-09-24T02:06:53Z

feat(pubsub): pub new flag, `-t {duration}` timeout

Eric Bower <me@erock.io> 2024-09-24T01:50:37Z
The default is no timeout.
 pubsub/cli.go | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
 1From c3f5de386adacb891c8562feb8e4f51c969a53a3 Mon Sep 17 00:00:00 2001
 2From: Eric Bower <me@erock.io>
 3Date: Mon, 23 Sep 2024 21:50:37 -0400
 4Subject: [PATCH 1/2] feat(pubsub): pub new flag, `-t {duration}` timeout
 5
 6The default is no timeout.
 7---
 8 pubsub/cli.go | 27 ++++++++++++++++++++++++++-
 9 1 file changed, 26 insertions(+), 1 deletion(-)
10
11diff --git a/pubsub/cli.go b/pubsub/cli.go
12index a0d8121..3eac378 100644
13--- a/pubsub/cli.go
14+++ b/pubsub/cli.go
15@@ -8,6 +8,7 @@ import (
16 	"log/slog"
17 	"strings"
18 	"text/tabwriter"
19+	"time"
20 
21 	"github.com/charmbracelet/ssh"
22 	"github.com/charmbracelet/wish"
23@@ -181,6 +182,7 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
24 				pubCmd := flagSet("pub", sesh)
25 				empty := pubCmd.Bool("e", false, "Send an empty message to subs")
26 				public := pubCmd.Bool("p", false, "Anyone can sub to this channel")
27+				timeout := pubCmd.String("t", "", "Timeout as a Go duration before cancelling the pub event. Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'. Default is no timeout.")
28 				if !flagCheck(pubCmd, repoName, cmdArgs) {
29 					return
30 				}
31@@ -215,8 +217,20 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
32 					})
33 				}
34 
35+				tt := *timeout
36+				wait := time.Duration(0)
37+				str := "no subs found ... waiting"
38+				if tt != "" {
39+					wait, err = time.ParseDuration(*timeout)
40+					if err != nil {
41+						wish.Errorln(sesh, err)
42+						return
43+					}
44+					str += " " + wait.String()
45+				}
46+
47 				if count == 0 {
48-					wish.Println(sesh, "no subs found ... waiting")
49+					wish.Println(sesh, str)
50 				}
51 
52 				go func() {
53@@ -224,6 +238,17 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
54 					pub.Cleanup()
55 				}()
56 
57+				go func() {
58+					// never cancel pub event
59+					if tt == "" {
60+						return
61+					}
62+
63+					time.Sleep(wait)
64+					pub.Cleanup()
65+					sesh.Close()
66+				}()
67+
68 				err = pubsub.PubSub.Pub(name, pub)
69 				wish.Println(sesh, "msg sent!")
70 				if err != nil {
71-- 
722.45.2
73

refactor(pubsub): use flags built-in Duration

Eric Bower <me@erock.io> 2024-09-24T02:06:24Z
 pubsub/cli.go | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
 1From a3ed6362310a516dacfa93bee7b38d1dd7214798 Mon Sep 17 00:00:00 2001
 2From: Eric Bower <me@erock.io>
 3Date: Mon, 23 Sep 2024 22:06:24 -0400
 4Subject: [PATCH 2/2] refactor(pubsub): use flags built-in Duration
 5
 6---
 7 pubsub/cli.go | 16 +++++-----------
 8 1 file changed, 5 insertions(+), 11 deletions(-)
 9
10diff --git a/pubsub/cli.go b/pubsub/cli.go
11index 3eac378..8d4d851 100644
12--- a/pubsub/cli.go
13+++ b/pubsub/cli.go
14@@ -182,7 +182,7 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
15 				pubCmd := flagSet("pub", sesh)
16 				empty := pubCmd.Bool("e", false, "Send an empty message to subs")
17 				public := pubCmd.Bool("p", false, "Anyone can sub to this channel")
18-				timeout := pubCmd.String("t", "", "Timeout as a Go duration before cancelling the pub event. Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'. Default is no timeout.")
19+				timeout := pubCmd.Duration("t", -1, "Timeout as a Go duration before cancelling the pub event. Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'. Default is no timeout.")
20 				if !flagCheck(pubCmd, repoName, cmdArgs) {
21 					return
22 				}
23@@ -218,15 +218,9 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
24 				}
25 
26 				tt := *timeout
27-				wait := time.Duration(0)
28 				str := "no subs found ... waiting"
29-				if tt != "" {
30-					wait, err = time.ParseDuration(*timeout)
31-					if err != nil {
32-						wish.Errorln(sesh, err)
33-						return
34-					}
35-					str += " " + wait.String()
36+				if tt > 0 {
37+					str += " " + tt.String()
38 				}
39 
40 				if count == 0 {
41@@ -240,11 +234,11 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
42 
43 				go func() {
44 					// never cancel pub event
45-					if tt == "" {
46+					if tt == -1 {
47 						return
48 					}
49 
50-					time.Sleep(wait)
51+					<-time.After(tt)
52 					pub.Cleanup()
53 					sesh.Close()
54 				}()
55-- 
562.45.2
57