https://kotlinlang.org logo
#kobweb
Title
# kobweb
j

jeff

03/14/2024, 4:09 PM
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

David Herman

03/14/2024, 5:28 PM
Check out the note at the end of this section? https://github.com/varabyte/kobweb#api-stream-conveniences
j

jeff

03/14/2024, 5:52 PM
Edit: Ignore my previous messages, I think I figured out my issue. Will update if not
d

David Herman

03/14/2024, 6:10 PM
No worries, good luck!
j

jeff

03/14/2024, 6:19 PM
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

David Herman

03/14/2024, 7:01 PM
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