Skip to content

Commit

Permalink
Add Lighthouse::stop
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Jun 1, 2024
1 parent 13cf116 commit 03174b4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lighthouse-client/src/lighthouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ impl<S> Lighthouse<S>
self.perform(&Verb::Unlink, dest_path, src_path).await
}

/// Stops the given stream.
pub async fn stop(&mut self, path: &[&str]) -> Result<ServerMessage<()>> {
self.perform(&Verb::Stop, path, ()).await
}

/// Performs a single request to the given path with the given payload.
#[tracing::instrument(skip(self, payload))]
pub async fn perform<P, R>(&mut self, verb: &Verb, path: &[&str], payload: P) -> Result<ServerMessage<R>>
Expand All @@ -202,6 +207,7 @@ impl<S> Lighthouse<S>
R: for<'de> Deserialize<'de> {
let request_id = self.send_request(&Verb::Stream, path, payload).await?;
let stream = self.receive_streaming(request_id).await?;
// TODO: Send STOP once dropped
Ok(stream)
}

Expand Down Expand Up @@ -245,9 +251,7 @@ impl<S> Lighthouse<S>
async fn receive_streaming<R>(&self, request_id: i32) -> Result<impl Stream<Item = Result<ServerMessage<R>>>>
where
R: for<'de> Deserialize<'de> {
// TODO: Add a stream guard that sends a STOP

Ok(self.receive(request_id).await?)
self.receive(request_id).await
}

async fn receive<R>(&self, request_id: i32) -> Result<impl Stream<Item = Result<ServerMessage<R>>>>
Expand Down

0 comments on commit 03174b4

Please sign in to comment.