MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / watch_sandboxes

Method watch_sandboxes

crates/openshell-driver-docker/src/lib.rs:1500–1543  ·  view source on GitHub ↗
(
        &self,
        _request: Request<WatchSandboxesRequest>,
    )

Source from the content-addressed store, hash-verified

1498 }
1499
1500 async fn watch_sandboxes(
1501 &self,
1502 _request: Request<WatchSandboxesRequest>,
1503 ) -> Result<Response<Self::WatchSandboxesStream>, Status> {
1504 // Subscribe before taking the initial snapshot so any event emitted
1505 // between the snapshot and this subscriber becoming active is still
1506 // delivered. Downstream consumers treat sandbox events as
1507 // idempotent (keyed by sandbox id), so a duplicate event is benign
1508 // while a missed one leaks state.
1509 let mut rx = self.events.subscribe();
1510 let initial = self.current_snapshots().await?;
1511 let (tx, out_rx) = mpsc::channel(WATCH_BUFFER);
1512 tokio::spawn(async move {
1513 for sandbox in initial {
1514 if tx
1515 .send(Ok(WatchSandboxesEvent {
1516 payload: Some(watch_sandboxes_event::Payload::Sandbox(
1517 WatchSandboxesSandboxEvent {
1518 sandbox: Some(sandbox),
1519 },
1520 )),
1521 }))
1522 .await
1523 .is_err()
1524 {
1525 return;
1526 }
1527 }
1528
1529 loop {
1530 match rx.recv().await {
1531 Ok(event) => {
1532 if tx.send(Ok(event)).await.is_err() {
1533 return;
1534 }
1535 }
1536 Err(broadcast::error::RecvError::Lagged(_)) => {}
1537 Err(broadcast::error::RecvError::Closed) => return,
1538 }
1539 }
1540 });
1541
1542 Ok(Response::new(Box::pin(ReceiverStream::new(out_rx))))
1543 }
1544}
1545
1546impl DockerProvisioningFailure {

Callers

nothing calls this directly

Calls 4

SandboxClass · 0.85
spawnFunction · 0.50
subscribeMethod · 0.45
current_snapshotsMethod · 0.45

Tested by

no test coverage detected