@@ -56,7 +56,7 @@ use super::{
5656 ApiClient , RequestResult , Tags ,
5757} ;
5858use crate :: {
59- api:: proto:: { BatchRequest , ImportByteStreamUpdate } ,
59+ api:: proto:: { BatchRequest , ImportByteStreamUpdate , ListBlobsItem } ,
6060 provider:: StreamContext ,
6161 store:: IROH_BLOCK_SIZE ,
6262 util:: temp_tag:: TempTag ,
@@ -835,32 +835,53 @@ impl ImportBaoHandle {
835835
836836/// A progress handle for a blobs list operation.
837837pub struct BlobsListProgress {
838- inner : future:: Boxed < irpc:: Result < mpsc:: Receiver < super :: Result < Hash > > > > ,
838+ inner : future:: Boxed < irpc:: Result < mpsc:: Receiver < ListBlobsItem > > > ,
839839}
840840
841841impl BlobsListProgress {
842842 fn new (
843- fut : impl Future < Output = irpc:: Result < mpsc:: Receiver < super :: Result < Hash > > > > + Send + ' static ,
843+ fut : impl Future < Output = irpc:: Result < mpsc:: Receiver < ListBlobsItem > > > + Send + ' static ,
844844 ) -> Self {
845845 Self {
846846 inner : Box :: pin ( fut) ,
847847 }
848848 }
849849
850850 pub async fn hashes ( self ) -> RequestResult < Vec < Hash > > {
851- let mut rx: mpsc :: Receiver < Result < Hash , super :: Error > > = self . inner . await ?;
851+ let mut rx = self . inner . await ?;
852852 let mut hashes = Vec :: new ( ) ;
853- while let Some ( item) = rx. recv ( ) . await ? {
854- hashes. push ( item?) ;
853+ loop {
854+ match rx. recv ( ) . await ? {
855+ Some ( ListBlobsItem :: Item ( hash) ) => hashes. push ( hash) ,
856+ Some ( ListBlobsItem :: Error ( cause) ) => return Err ( cause. into ( ) ) ,
857+ Some ( ListBlobsItem :: Done ) => break ,
858+ None => return Err ( super :: Error :: other ( "unexpected end of stream" ) . into ( ) ) ,
859+ }
855860 }
856861 Ok ( hashes)
857862 }
858863
859864 pub async fn stream ( self ) -> irpc:: Result < impl Stream < Item = super :: Result < Hash > > > {
860865 let mut rx = self . inner . await ?;
861866 Ok ( Gen :: new ( |co| async move {
862- while let Ok ( Some ( item) ) = rx. recv ( ) . await {
863- co. yield_ ( item) . await ;
867+ loop {
868+ match rx. recv ( ) . await {
869+ Ok ( Some ( ListBlobsItem :: Item ( hash) ) ) => co. yield_ ( Ok ( hash) ) . await ,
870+ Ok ( Some ( ListBlobsItem :: Error ( cause) ) ) => {
871+ co. yield_ ( Err ( cause) ) . await ;
872+ break ;
873+ }
874+ Ok ( Some ( ListBlobsItem :: Done ) ) => break ,
875+ Ok ( None ) => {
876+ co. yield_ ( Err ( super :: Error :: other ( "unexpected end of stream" ) . into ( ) ) )
877+ . await ;
878+ break ;
879+ }
880+ Err ( cause) => {
881+ co. yield_ ( Err ( cause. into ( ) ) ) . await ;
882+ break ;
883+ }
884+ }
864885 }
865886 } ) )
866887 }
0 commit comments