From 54b03a8dada6e3b8eeac5a7b7e84249127063088 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 16 Jun 2018 20:47:42 +0200 Subject: [PATCH] fix(main): Attempt to read with next_record before waiting Without this fix new records are only "pushed out" when something appends to the journal. --- src/main.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d740cc178..75e0274c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -220,6 +220,18 @@ impl From for LogEntry { } } +/// Attempt to read from the journal. If no new entry is present, +/// await the next one up to the specified timeout. +fn receive_next_record(timeout: Duration, journal: &mut Journal) + -> Result> { + let next_record = journal.next_record()?; + if next_record.is_some() { + return Ok(next_record); + } + + Ok(journal.await_next_record(Some(timeout))?) +} + /// This function starts a double-looped, blocking receiver. It will /// buffer messages for half a second before flushing them to /// Stackdriver. @@ -239,7 +251,7 @@ fn receiver_loop(mut journal: Journal) -> Result<()> { break; } - if let Ok(Some(entry)) = journal.await_next_record(Some(iteration)) { + if let Ok(Some(entry)) = receive_next_record(iteration, &mut journal) { trace!("Received a new entry"); buf.push(entry.into()); }