about summary refs log tree commit diff
path: root/tvix/store/src/blobservice/grpc.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-05-22T16·40+0300
committerclbot <clbot@tvl.fyi>2023-05-24T09·01+0000
commitf4a7b325e9d44fc2fd002e7cf2eb9361528017a9 (patch)
tree50b409d4c195de189c7ecd0b9c1bbd5f64b2a84c /tvix/store/src/blobservice/grpc.rs
parent2d214eacc508604aebaa4deaec97d3842286ed30 (diff)
feat(tvix/store/blobsvc): add constructors r/6186
Change-Id: I55e06bf4e8a11dc2caf92c597558f1b820b42566
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8610
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/store/src/blobservice/grpc.rs')
-rw-r--r--tvix/store/src/blobservice/grpc.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/tvix/store/src/blobservice/grpc.rs b/tvix/store/src/blobservice/grpc.rs
index 9c07345839e3..0b08fbf46ad9 100644
--- a/tvix/store/src/blobservice/grpc.rs
+++ b/tvix/store/src/blobservice/grpc.rs
@@ -22,7 +22,29 @@ pub struct GRPCBlobService {
     grpc_client: proto::blob_service_client::BlobServiceClient<Channel>,
 }
 
-// TODO: provide some contstructors
+impl GRPCBlobService {
+    /// construct a [GRPCBlobService] from a [proto::blob_service_client::BlobServiceClient<Channel>],
+    /// and a [tokio::runtime::Handle].
+    pub fn new(
+        grpc_client: proto::blob_service_client::BlobServiceClient<Channel>,
+        tokio_handle: tokio::runtime::Handle,
+    ) -> Self {
+        Self {
+            tokio_handle,
+            grpc_client,
+        }
+    }
+    /// construct a [GRPCBlobService] from a [proto::blob_service_client::BlobServiceClient<Channel>].
+    /// panics if called outside the context of a tokio runtime.
+    pub fn from_client(
+        grpc_client: proto::blob_service_client::BlobServiceClient<Channel>,
+    ) -> Self {
+        Self {
+            tokio_handle: tokio::runtime::Handle::current(),
+            grpc_client,
+        }
+    }
+}
 
 impl BlobService for GRPCBlobService {
     type BlobReader = Box<dyn io::Read + Send>;