Closed
Description
See https://github.com/kaibyao/tokio-postgres-tosql-multithread-issue for a reference implementation of this problem.
// example endpoint using actix_web 1.0
async fn index() -> Result<HttpResponse, Error> {
// ...
let prepared_values: Vec<&dyn ToSql> = vec![&true];
let rows = client.query(&statement, &prepared_values).collect().compat().await;
let rows: Vec<i32> = rows.unwrap().into_iter().map(|row| row.get(0)).collect();
Ok(HttpResponse::build(StatusCode::OK).json(rows))
}
// in another thread
fn returns_future() -> impl Future01<Item = HttpResponse, Error = Error> {
index().boxed().compat()
// ^^^^^^^ `dyn tokio_postgres::types::ToSql` cannot be shared between threads safely
}
What's the best way to pass Vec<&dyn ToSql>
(for prepared statements) in multi-threaded environments?
The following don't work:
- Using
&(dyn ToSql + Send)
instead of&dyn ToSql
- Creating a "wrapper" trait
ToSqlSend
that does haveSend
andToSql
and changing&dyn ToSql
to&dyn ToSqlSend
.
Metadata
Metadata
Assignees
Labels
No labels