@@ -70,9 +70,11 @@ use diesel::backend::Backend;
70
70
use diesel:: query_builder:: { AsQuery , QueryFragment , QueryId } ;
71
71
use diesel:: row:: Row ;
72
72
use diesel:: { ConnectionResult , QueryResult } ;
73
- use futures:: future:: BoxFuture ;
74
73
use futures:: { Future , Stream } ;
75
74
75
+ pub use scoped_futures;
76
+ use scoped_futures:: ScopedBoxFuture ;
77
+
76
78
#[ cfg( feature = "mysql" ) ]
77
79
mod mysql;
78
80
#[ cfg( feature = "postgres" ) ]
@@ -180,7 +182,7 @@ where
180
182
/// ```rust
181
183
/// # include!("doctest_setup.rs");
182
184
/// use diesel::result::Error;
183
- /// use futures::FutureExt ;
185
+ /// use scoped_futures::ScopedFutureExt ;
184
186
///
185
187
/// # #[tokio::main(flavor = "current_thread")]
186
188
/// # async fn main() {
@@ -200,7 +202,7 @@ where
200
202
/// assert_eq!(vec!["Sean", "Tess", "Ruby"], all_names);
201
203
///
202
204
/// Ok(())
203
- /// }.boxed ()).await?;
205
+ /// }.scope_boxed ()).await?;
204
206
///
205
207
/// conn.transaction::<(), _, _>(|conn| async move {
206
208
/// diesel::insert_into(users)
@@ -214,18 +216,18 @@ where
214
216
/// // If we want to roll back the transaction, but don't have an
215
217
/// // actual error to return, we can return `RollbackTransaction`.
216
218
/// Err(Error::RollbackTransaction)
217
- /// }.boxed ()).await;
219
+ /// }.scope_boxed ()).await;
218
220
///
219
221
/// let all_names = users.select(name).load::<String>(conn).await?;
220
222
/// assert_eq!(vec!["Sean", "Tess", "Ruby"], all_names);
221
223
/// # Ok(())
222
224
/// # }
223
225
/// ```
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 >
225
227
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 ,
229
231
{
230
232
Self :: TransactionManager :: transaction ( self , callback) . await
231
233
}
0 commit comments