From 8c0b2622822e2896236af766041bb3dc90dfcd7d Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 27 Dec 2024 20:13:35 +0100 Subject: [PATCH] Test SSE --- server/sse.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/server/sse.go b/server/sse.go index 715575a..e7edd17 100644 --- a/server/sse.go +++ b/server/sse.go @@ -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() }