Is there a safe way to push this work off to a background thread?
To ensure the database is not accessed while the background thread is working, I call stop on both pull and push replications beforehand and set the main thread's reference to the database to nil immediately after.