I know if I declare an `ApiStream` as a top-level ...
# kobweb
j
I know if I declare an
ApiStream
as a top-level variable, it is set up automatically. But is there a way to manually add one after startup, so that I can defer its initialization?
d
Check out the note at the end of this section? https://github.com/varabyte/kobweb#api-stream-conveniences
j
Edit: Ignore my previous messages, I think I figured out my issue. Will update if not
d
No worries, good luck!
j
tldr: not urgent I corrected some flawed assumptions, but didn't quite figure this out specifically. On the client,
ApiStream
has a
.connect()
method to allow you to connect it whenever you want. But on the server, I see only the 'magic' that happens when you declare it as a top-level with
@Api
. I'm still curious if there's a way to defer ApiStreams on the server, although I'm thinking it might make more sense in my particular case to set them up immediately and then defer the code that actually sends anything to them (so that I won't drop connections that come in too fast)
d
The
ApiStream
object on the server is very lightweight. You should think of it like
Api
methods actually -- once registered, they're always there, waiting to respond to client messages.
👍 1