default_state_function = function (recent_doc, initial_doc) {
        return (
          recent_doc._replication_state === 'completed' ||
              recent_doc._replication_state === 'error'
        );
    }
Waits for a replication operation to enter a specific state.
waitReplication polls the _replication database using the
doc provided, and evaluates state_function(doc) at each iteration.
This function stops polling and invokes callback when the
state_function evaluates to true. If state_function is not
provided, waitReplication waits for the doc's _replication_state
to change from 'triggered' to 'completed' (or 'error').

If you're running behind a virtual host you'll need to set up
appropriate rewrites to /_replicator, which will also mean turning
off safe rewrites.

This function only works with CouchDB >= 1.1, since it uses the
_replicator database.

@name wait(doc, [options, state_function], callback)
@param {Object} doc
@param {Function} state_function (optional)
@param {Function} callback
@api public