~anjan/public-inbox

mnc: Remove goroutine v1 APPLIED

Martin Vahlensieck
Martin Vahlensieck: 1
 Remove goroutine

 1 files changed, 19 insertions(+), 25 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~anjan/public-inbox/patches/24726/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH mnc] Remove goroutine Export this patch

Martin Vahlensieck
---
 mnc.go | 44 +++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/mnc.go b/mnc.go
index c565d3d..43b8b2b 100644
--- a/mnc.go
+++ b/mnc.go
@@ -27,35 +27,29 @@ func init() {
func main() {
	// seed with a large number that rtcwake can still handle
	m := 268435455
	d := make(chan struct{})
	s := bufio.NewScanner(os.Stdin)

	go func() {
		n := time.Now()
		for s.Scan() {
			//we need to only get the first 5 fields otherwise
			//the cron library will try to parse the rest too
			fields := strings.Split(strings.TrimSpace(s.Text()), " ")
			l := strings.Join(fields[:5], " ")
			p, e := cron.ParseUTC(l)
			if e == nil {
				t, e := p.Next(n)
				if e != nil {
					log.Fatal(e)
				}
				i := int(t.Sub(n).Seconds())
				if i < m {
					m = i
				}
				log.Print(i)
			} else {
				log.Print(e)
	n := time.Now()
	for s.Scan() {
		//we need to only get the first 5 fields otherwise
		//the cron library will try to parse the rest too
		fields := strings.Split(strings.TrimSpace(s.Text()), " ")
		l := strings.Join(fields[:5], " ")
		p, e := cron.ParseUTC(l)
		if e == nil {
			t, e := p.Next(n)
			if e != nil {
				log.Fatal(e)
			}
			i := int(t.Sub(n).Seconds())
			if i < m {
				m = i
			}
			log.Print(i)
		} else {
			log.Print(e)
		}
		d <- struct{}{}
	}()

	<-d
	}

	fmt.Println(m)

-- 
2.28.0
Ya, The goroutine is largely unneccesary. It would also be nice to have
nicer variable names too =).

Thanks for the patch! Applied.

Sincerely,
Anjan
-- 
w:] www.momi.ca
pgp:] https://momi.ca/publickey.txt