add proper pubsub

This commit is contained in:
kiwiidb
2022-04-06 18:00:04 +02:00
parent 45e0c48f1f
commit a5ae01a5f2
5 changed files with 65 additions and 20 deletions

View File

@@ -33,7 +33,8 @@ func (controller *InvoiceStreamController) StreamInvoices(c echo.Context) error
return err
}
invoiceChan := make(chan models.Invoice)
controller.svc.InvoiceSubscribers[userId] = invoiceChan
reqId := c.Response().Header().Get(echo.HeaderXRequestID)
controller.svc.InvoicePubSub.Subscribe(reqId, userId, invoiceChan)
ctx := c.Request().Context()
upgrader := websocket.Upgrader{}
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
@@ -80,5 +81,6 @@ SocketLoop:
}
}
}
controller.svc.InvoicePubSub.Unsubscribe(reqId, userId)
return nil
}