Quantcast
Channel: Injecting a Diesel connection into an Iron middleware - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by sgrif for Injecting a Diesel connection into an Iron middleware

$
0
0

This answer will certainly solve the problem, but it's not optimal. As mentioned, you can't share a single connection as it's not thread safe. However, while wrapping it in a Mutex makes it thread-safe, it would force all the server threads to use a single connection. Instead, you want to use a connection pool.

You can accomplish this with the r2d2 and r2d2-diesel crates. This will establish multiple connections as needed, and reuse them when possible in a thread safe manner.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>