This commit is contained in:
ekzyis 2024-12-27 20:13:35 +01:00
parent a5a6a1711a
commit 8c0b262282
1 changed files with 21 additions and 2 deletions

View File

@ -53,6 +53,11 @@ func sseHandler(invSrc chan *lightning.Invoice) echo.HandlerFunc {
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
i := 0
ticker2 := time.NewTicker(1 * time.Second)
defer ticker2.Stop()
for {
select {
case <-c.Request().Context().Done():
@ -66,11 +71,19 @@ func sseHandler(invSrc chan *lightning.Invoice) echo.HandlerFunc {
if err := event.MarshalTo(w); err != nil {
return err
}
case inv := <-invSrc:
case <-ticker2.C:
buf := templ.GetBuffer()
defer templ.ReleaseBuffer(buf)
if err := components.Zap(inv).Render(c.Request().Context(), buf); err != nil {
inv := lightning.Invoice{
PaymentHash: fmt.Sprintf("test-%d", i),
Description: "test",
Msats: 1000,
CreatedAt: time.Now(),
ConfirmedAt: time.Now(),
}
if err := components.Zap(&inv).Render(c.Request().Context(), buf); err != nil {
return err
}
@ -85,6 +98,12 @@ func sseHandler(invSrc chan *lightning.Invoice) echo.HandlerFunc {
if err := event.MarshalTo(w); err != nil {
return err
}
i += 1
if i > 10 {
ticker2.Stop()
}
}
w.Flush()
}