wrote courier

This commit is contained in:
Jay
2026-05-10 14:28:53 -04:00
parent f3b9e814e5
commit b87d8f8fb1
2 changed files with 193 additions and 7 deletions
+19
View File
@@ -3,6 +3,7 @@ package prism
import (
"container/list"
"context"
"fmt"
"git.wisehodl.dev/jay/go-mana-component"
"log/slog"
"sync"
@@ -88,6 +89,7 @@ type Courier struct {
ctx context.Context
cancel context.CancelFunc
mu sync.Mutex
wg sync.WaitGroup
logger *slog.Logger
}
@@ -199,6 +201,7 @@ func (c *Courier) HandleDisconnect() {
}
func (c *Courier) Close() {
c.command(&cmdCloseCourier{})
c.cancel()
c.wg.Wait()
}
@@ -208,6 +211,7 @@ func (c *Courier) Close() {
func (c *Courier) command(cmd courierCommand) {
select {
case <-c.ctx.Done():
fmt.Println("here")
case c.cmd <- cmd:
}
}
@@ -364,3 +368,18 @@ func (cmd cmdHandleSendResult) apply(c *Courier) {
c.doneOnce(cmd.traveller)
}
}
type cmdCloseCourier struct{}
func (cmd cmdCloseCourier) apply(c *Courier) {
// cancel remaining letters
for {
t, ok := c.pop()
if !ok {
break
}
t.letter.cancel()
t.setMissedAt(time.Now())
c.doneOnce(t)
}
}