@@ -70,9 +70,11 @@ use diesel::backend::Backend;
7070use diesel:: query_builder:: { AsQuery , QueryFragment , QueryId } ;
7171use diesel:: row:: Row ;
7272use diesel:: { ConnectionResult , QueryResult } ;
73- use futures:: future:: BoxFuture ;
7473use futures:: { Future , Stream } ;
7574
75+ pub use scoped_futures;
76+ use scoped_futures:: ScopedBoxFuture ;
77+
7678#[ cfg( feature = "mysql" ) ]
7779mod mysql;
7880#[ cfg( feature = "postgres" ) ]
@@ -180,7 +182,7 @@ where
180182 /// ```rust
181183 /// # include!("doctest_setup.rs");
182184 /// use diesel::result::Error;
183- /// use futures::FutureExt ;
185+ /// use scoped_futures::ScopedFutureExt ;
184186 ///
185187 /// # #[tokio::main(flavor = "current_thread")]
186188 /// # async fn main() {
@@ -200,7 +202,7 @@ where
200202 /// assert_eq!(vec!["Sean", "Tess", "Ruby"], all_names);
201203 ///
202204 /// Ok(())
203- /// }.boxed ()).await?;
205+ /// }.scope_boxed ()).await?;
204206 ///
205207 /// conn.transaction::<(), _, _>(|conn| async move {
206208 /// diesel::insert_into(users)
@@ -214,18 +216,18 @@ where
214216 /// // If we want to roll back the transaction, but don't have an
215217 /// // actual error to return, we can return `RollbackTransaction`.
216218 /// Err(Error::RollbackTransaction)
217- /// }.boxed ()).await;
219+ /// }.scope_boxed ()).await;
218220 ///
219221 /// let all_names = users.select(name).load::<String>(conn).await?;
220222 /// assert_eq!(vec!["Sean", "Tess", "Ruby"], all_names);
221223 /// # Ok(())
222224 /// # }
223225 /// ```
224- async fn transaction < R , E , F > ( & mut self , callback : F ) -> Result < R , E >
226+ async fn transaction < ' a , R , E , F > ( & mut self , callback : F ) -> Result < R , E >
225227 where
226- F : FnOnce ( & mut Self ) -> BoxFuture < Result < R , E > > + Send ,
227- E : From < diesel:: result:: Error > + Send ,
228- R : Send ,
228+ F : for < ' r > FnOnce ( & ' r mut Self ) -> ScopedBoxFuture < ' a , ' r , Result < R , E > > + Send + ' a ,
229+ E : From < diesel:: result:: Error > + Send + ' a ,
230+ R : Send + ' a ,
229231 {
230232 Self :: TransactionManager :: transaction ( self , callback) . await
231233 }
0 commit comments