@@ -69,42 +69,45 @@ impl Client {
6969 op : T ,
7070 session : impl Into < Option < & mut ClientSession > > ,
7171 ) -> Result < T :: O > {
72- // TODO RUST-9: allow unacknowledged write concerns
73- if !op. is_acknowledged ( ) {
74- return Err ( ErrorKind :: InvalidArgument {
75- message : "Unacknowledged write concerns are not supported" . to_string ( ) ,
72+ Box :: pin ( async {
73+ // TODO RUST-9: allow unacknowledged write concerns
74+ if !op. is_acknowledged ( ) {
75+ return Err ( ErrorKind :: InvalidArgument {
76+ message : "Unacknowledged write concerns are not supported" . to_string ( ) ,
77+ }
78+ . into ( ) ) ;
7679 }
77- . into ( ) ) ;
78- }
79- match session. into ( ) {
80- Some ( session ) => {
81- if ! Arc :: ptr_eq ( & self . inner , & session. client ( ) . inner ) {
82- return Err ( ErrorKind :: InvalidArgument {
83- message : "the session provided to an operation must be created from the \
84- same client as the collection/database"
85- . into ( ) ,
80+ match session . into ( ) {
81+ Some ( session ) => {
82+ if ! Arc :: ptr_eq ( & self . inner , & session. client ( ) . inner ) {
83+ return Err ( ErrorKind :: InvalidArgument {
84+ message : "the session provided to an operation must be created from \
85+ the same client as the collection/database"
86+ . into ( ) ,
87+ }
88+ . into ( ) ) ;
8689 }
87- . into ( ) ) ;
88- }
8990
90- if let Some ( SelectionCriteria :: ReadPreference ( read_preference) ) =
91- op. selection_criteria ( )
92- {
93- if session. in_transaction ( ) && read_preference != & ReadPreference :: Primary {
94- return Err ( ErrorKind :: Transaction {
95- message : "read preference in a transaction must be primary" . into ( ) ,
91+ if let Some ( SelectionCriteria :: ReadPreference ( read_preference) ) =
92+ op. selection_criteria ( )
93+ {
94+ if session. in_transaction ( ) && read_preference != & ReadPreference :: Primary {
95+ return Err ( ErrorKind :: Transaction {
96+ message : "read preference in a transaction must be primary" . into ( ) ,
97+ }
98+ . into ( ) ) ;
9699 }
97- . into ( ) ) ;
98100 }
101+ self . execute_operation_with_retry ( op, Some ( session) ) . await
102+ }
103+ None => {
104+ let mut implicit_session = self . start_implicit_session ( & op) . await ?;
105+ self . execute_operation_with_retry ( op, implicit_session. as_mut ( ) )
106+ . await
99107 }
100- self . execute_operation_with_retry ( op, Some ( session) ) . await
101- }
102- None => {
103- let mut implicit_session = self . start_implicit_session ( & op) . await ?;
104- self . execute_operation_with_retry ( op, implicit_session. as_mut ( ) )
105- . await
106108 }
107- }
109+ } )
110+ . await
108111 }
109112
110113 /// Execute the given operation, returning the implicit session created for it if one was.
@@ -114,10 +117,13 @@ impl Client {
114117 & self ,
115118 op : T ,
116119 ) -> Result < ( T :: O , Option < ClientSession > ) > {
117- let mut implicit_session = self . start_implicit_session ( & op) . await ?;
118- self . execute_operation_with_retry ( op, implicit_session. as_mut ( ) )
119- . await
120- . map ( |result| ( result, implicit_session) )
120+ Box :: pin ( async {
121+ let mut implicit_session = self . start_implicit_session ( & op) . await ?;
122+ self . execute_operation_with_retry ( op, implicit_session. as_mut ( ) )
123+ . await
124+ . map ( |result| ( result, implicit_session) )
125+ } )
126+ . await
121127 }
122128
123129 /// Selects a server and executes the given operation on it, optionally using a provided
0 commit comments