use database::Database;
use endpoint::execute::ExecuteError;

use std::io;

pub fn execute_enumerate<R>(journal_name: &[u8], database: &Database,
                            mut respond: R) -> Result<(), ExecuteError>
    where R: for<'a> FnMut(&'a [u8]) -> io::Result<()> {
    let concurrent_journal = database.get_journal(journal_name)?;
    let mut journal = concurrent_journal.read()?;
    for entry in journal.iter()? {
        respond(&entry?)?;
    }
    Ok(())
}
