Repository: libsql/libsql
File: libsql/src/database.rs (Rust)

Code before:
                    writer,
                    self.max_write_replication_index.clone(),
                );
                let conn = std::sync::Arc::new(remote);

                Ok(Connection { conn })
            }

            #[cfg(feature = "sync")]
            DbType::Offline {
                db,
                remote_writes,
                read_your_writes,
                url,
                auth_token,
                connector,
            } => {
                use crate::{
                    hrana::{connection::HttpConnection, hyper::HttpSender},
                    local::impls::LibsqlConnection,
                    replication::connection::State,
                    sync::connection::SyncedConnection,
                };
                use tokio::sync::Mutex;

                let local = db.connect()?;

                if *remote_writes {
                    let synced = SyncedConnection {
                        local,
                        remote: HttpConnection::new(
                            url.clone(),
                            auth_token.clone(),
                            HttpSender::new(connector.clone(), None),
                        ),
                        read_your_writes: *read_your_writes,
                        context: db.sync_ctx.clone().unwrap(),
                        state: std::sync::Arc::new(Mutex::new(State::Init)),
                    };

                    let conn = std::sync::Arc::new(synced);
                    return Ok(Connection { conn });
                }

                let conn = std::sync::Arc::new(LibsqlConnection { conn: local });
                Ok(Connection { conn })
            }

            #[cfg(feature = "remote")]
            DbType::Remote {
                url,

Review comment (suggestion):
This breaks Db initialization under Actix due to its blocking nature. It forces the user to separate the db initialization out of the actix main and create a custom main which initializes the db first in a multi-threaded Tokio runtime and then passes it to Actix.

Code after:
                    writer,
                    self.max_write_replication_index.clone(),
                );
                let conn = std::sync::Arc::new(remote);

                Ok(Connection { conn })
            }

            #[cfg(feature = "sync")]
            DbType::Offline {
                db,
                remote_writes,
                read_your_writes,
                url,
                auth_token,
                connector,
            } => {
                use crate::{
                    hrana::{connection::HttpConnection, hyper::HttpSender},
                    local::impls::LibsqlConnection,
                    replication::connection::State,
                    sync::connection::SyncedConnection,
                };
                use tokio::sync::Mutex;

                let _ = tokio::task::block_in_place(move || {
                    let rt = tokio::runtime::Builder::new_current_thread()
                        .enable_all()
                        .build()
                        .unwrap();
                    rt.block_on(async {
                        // we will ignore if any errors occurred during the bootstrapping the db,
                        // because the client could be offline when trying to connect.
                        let _ = db.bootstrap_db().await;
                    })
                });

                let local = db.connect()?;

                if *remote_writes {
                    let synced = SyncedConnection {
                        local,
                        remote: HttpConnection::new(
                            url.clone(),
                            auth_token.clone(),
                            HttpSender::new(connector.clone(), None),
                        ),
                        read_your_writes: *read_your_writes,
                        context: db.sync_ctx.clone().unwrap(),
                        state: std::sync::Arc::new(Mutex::new(State::Init)),
                    };