Runs queued `read` and `write` tasks.

Errors are caught and thrown by default.
If a `.catch` function has been defined
it is called instead.

@private
function flush(fastdom) {

    var reads = fastdom.reads.splice(0, fastdom.reads.length),
        writes = fastdom.writes.splice(0, fastdom.writes.length),
        error;

    try {
        runTasks(reads);
        runTasks(writes);
    } catch (e) { error = e; }

    fastdom.scheduled = false;

    // If the batch errored we may still have tasks queued
    if (fastdom.reads.length || fastdom.writes.length) { scheduleFlush(fastdom); }

    if (error) {
        if (fastdom.catch) { fastdom.catch(error); }
        else { throw error; }
    }
}