ref: cf198b58e2b24938444437dbc7fc6f27f6590b67
parent: 213ae0b56ce5cc1c2d618d9155fa851039e78712
author: penny <penny@limitedideas.org>
date: Wed Aug 20 16:49:40 EDT 2025
Messy status queuing system
--- a/dispatch.go
+++ b/dispatch.go
@@ -2,22 +2,51 @@
import (
"fmt"
-
+ "time"
+
"github.com/mattn/go-mastodon"
)
-func (hc *Hellclient) clientDispatch() { +func (hc *Hellclient) queueManager() {+
+}
+
+func (hc *Hellclient) clientDispatch() {+ var tootQueue []*mastodon.Toot
+ var lastfire time.Time
+ var lastreceive time.Time
for { select {- case statustoot := <- hc.dispatch:
- hc.lock()
+ case statustoot := <-hc.dispatch:
+ tootQueue = append(tootQueue, statustoot)
+ default:
+ if len(tootQueue) > 1 {+ fmt.Printf("Got %v lines fast!\n", len(tootQueue))+ tootQueue = nil
+ }
+ if 1 > len(tootQueue) {+ statustoot := <-hc.dispatch
+ tootQueue = append(tootQueue, statustoot)
+ break
+ }
+ if time.Since(lastfire) < hc.preferences.apidelay {+ time.Sleep(hc.preferences.apidelay - time.Since(lastfire))
+ break
+ }
+ var status *mastodon.Status
+ for _, toot := range tootQueue {+ lastfire = time.Now()
var err error
- status, err := postStatusDetailed(*hc.client, *statustoot)
+ fmt.Printf("%v\n", toot.Status)+ hc.lock()
+ hc.recentpost = status
+ hc.unlock()
if err != nil {fmt.Println(err)
}
- hc.recentpost = status
- hc.unlock()
+ tootQueue = tootQueue[1:]
+ break
+ }
}
}
}
@@ -28,4 +57,4 @@
func (hc *Hellclient) dispatchReply(posttext string, replyto mastodon.ID, postItem *mastodon.Status) {hc.dispatch <- postReply(posttext, replyto, hc.currentuser.ID, postItem)
-}
\ No newline at end of file
+}
--- a/hellclient.go
+++ b/hellclient.go
@@ -5,6 +5,7 @@
"io"
"strings"
"sync"
+ "time"
"github.com/ergochat/readline"
"github.com/mattn/go-mastodon"
@@ -24,6 +25,7 @@
dispatch chan *mastodon.Toot
block sync.Mutex
recentpost *mastodon.Status
+ preferences *Hellprefs
homeMap map[string]*mastodon.Status
urlMap map[string][]string
@@ -31,6 +33,10 @@
actionBuffer []func()
}
+type Hellprefs struct {+ apidelay time.Duration
+}
+
func NewHellclient() (*Hellclient, error) { rl, err := readline.New("Hell> ")rl.CaptureExitSignal()
@@ -46,12 +52,13 @@
if err != nil {return nil, err
}
-
- dispatch := make(chan *mastodon.Toot)
+ dispatch := make(chan *mastodon.Toot, 15)
+
homeMap := make(map[string]*mastodon.Status)
debugMap := make(map[string]interface{})urlMap := make(map[string][]string)
+ prefs := &Hellprefs{apidelay: time.Second * 3} return &Hellclient{rl: rl,homeMap: homeMap,
debugMap: debugMap,
@@ -60,6 +67,7 @@
client: client,
currentuser: currentuser,
dispatch: dispatch,
+ preferences: prefs,
}, nil
}
--
⑨