internal void ReplaceOperationQueue(SqliteOperationQueue queue)
        {
            _initializer.Wait();

            opQueue.Dispose();

            opQueue = queue;
            opQueue.Start();
        }
        public void Dispose()
        {
            var disp = Interlocked.Exchange(ref queueThread, null);

            if (disp == null)
            {
                return;
            }

            var cleanup = Observable.Start(() =>
            {
                // NB: While we intentionally dispose the operation queue
                // from a background thread so that we don't park the UI
                // while we're waiting for background operations to
                // complete, we must serialize calls to sqlite3_close or
                // else SQLite3 will start throwing back "busy" at us.
                //
                // We intentionally serialize even the shutdown of the
                // background queue to be extra paranoid about not getting
                // 'busy' while cleaning up.
                lock (disposeGate)
                {
                    disp.Dispose();
                    opQueue.Dispose();
                    Connection.Dispose();
                }
            }, Scheduler);

            cleanup.Multicast(shutdown).PermaRef();
            disposed = true;
        }