Getting tags associated with a Hibernatable WebSocket

Also, random question but if we support this.state.getTags(webSocket) for hibernatable websockets, would y'all want it to throw an error if you give it a non-hibernatable websocket? Or would you just want it to give you an empty array?
5 Replies
Milan
MilanOP•11mo ago
If you're in a webSocketX() handler then the websocket you're given through the function arg is obviously hibernatable. If you get your websockets from this.state.getWebSockets(), you also know they're hibernatable. However, if you're saving them in some property on your DO I figure you could lose track if you use both regular and hibernatable ws in a single namespace. Just want to see if any of y'all have an opinion 🙂
zegevlier
zegevlier•11mo ago
I think it makes more sense for it to throw than to return an empty list. The tag list for the non-hibernatable websocket isn't empty, it just doesn't exist. This would also create a way to differentiate between the two (if it throws it's a non-hibernatable, if it doesn't throw it's hibrenatable), which could be useful.
Milan
MilanOP•11mo ago
Agreed, thanks for your input!
WillTolmie
WillTolmie•11mo ago
Isn’t using exceptions for flow control in normal execution an ant pattern? I’d have thought just returning null be more natural?
Milan
MilanOP•10mo ago
Sorry, didn't see this! I suppose the broader point here is that if your script ever does throw this error, it's an indication that you're doing something wrong (and it's fixable). You shouldn't be giving state.getTags() a regular websocket because it's essentially the wrong argument type. If we were just to return null, developers might assume that's the same as "no tags", and then continue on without realizing they're intermingling separate APIs.
Want results from more Discord servers?
Add your server