p2panda_net/iroh_endpoint/
supervisor.rs1use ractor::ActorCell;
4use ractor::thread_local::{ThreadLocalActor, ThreadLocalActorSpawner};
5
6use crate::iroh_endpoint::actors::IrohEndpoint;
7use crate::iroh_endpoint::{Builder, Endpoint, EndpointError};
8use crate::supervisor::{ChildActor, ChildActorFut, Supervisor};
9
10impl Builder {
11 pub async fn spawn_linked(self, supervisor: &Supervisor) -> Result<Endpoint, EndpointError> {
12 let endpoint = Endpoint::new(None, self.build_args());
13 supervisor.start_child_actor(endpoint.clone()).await?;
14 Ok(endpoint)
15 }
16}
17
18impl ChildActor for Endpoint {
19 fn on_start(
20 &self,
21 supervisor: ActorCell,
22 thread_pool: ThreadLocalActorSpawner,
23 ) -> ChildActorFut<'_> {
24 Box::pin(async move {
25 let (actor_ref, _) =
27 IrohEndpoint::spawn_linked(None, self.args.clone(), supervisor, thread_pool)
28 .await?;
29
30 let mut inner = self.inner.write().await;
32 inner.actor_ref.replace(actor_ref.clone());
33
34 Ok(actor_ref.into())
35 })
36 }
37}