-
Notifications
You must be signed in to change notification settings - Fork 261
Description
It is kind of annoying, that while setting up everything I already need to bring async in. Conceptually spawning a router should not need to block on anything and indeed, when looking at the source code of fn spawn
, the only part that does .await
:
if let Err(err) = self.endpoint.set_alpns(alpns) {
shutdown(&self.endpoint, protocols.clone()).await;
return Err(err);
}
It seems ... weird. Why do we need to block on anything on init error here, but we're fine in the success case? (If the spawn
was succesful, and Router
immediately drops, somehow everything shuts down OK without async-drop, or await).
In case you wonder why "async" is a problem. I need to pass some reference to my "App" to the protocols as a state, so it can interact with the app as a whole. But I need to put the resulting router
somewhere ... likely ... in the "App" itself.
Typically I use Arc::new_cyclic
for stuff like that, so one can have a single top-level App, that can pass a weak reference to all components. But new_cyclic
is a blocking function, so I can't call spawn.await
that easily. I have worked it around with OnceLock
, but
Metadata
Metadata
Assignees
Labels
Type
Projects
Status