Skip to content

Commit 55adede

Browse files
Marcel Hermnexoscp
authored andcommitted
Add SkipN method to allow follow-decoupled entry skipping
1 parent ebd2c33 commit 55adede

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

sdjournal/read.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,25 @@ process:
256256
}
257257
}
258258

259+
// SkipN skips the next n entries and returns the number of skipped entries and an eventual error.
260+
func (r *JournalReader) SkipN(n int) (int, error) {
261+
var i int
262+
for i := 1; i <= n; i++ {
263+
c, err := r.journal.Next()
264+
if err != nil {
265+
return i, err
266+
} else if c == 0 {
267+
return i, nil
268+
}
269+
}
270+
return i, nil
271+
}
272+
259273
// FollowTail synchronously follows the JournalReader, writing each new journal entry to entries.
260274
// It will start from the next unread entry.
261275
func (r *JournalReader) FollowTail(entries chan *JournalEntry) error {
262276
defer close(entries)
263277

264-
// skip first entry which has already been read
265-
if _, err := r.journal.Next(); err != nil {
266-
return err
267-
}
268-
269278
for {
270279
status := r.journal.Wait(200 * time.Millisecond)
271280
if status != SD_JOURNAL_APPEND && status != SD_JOURNAL_INVALIDATE {

0 commit comments

Comments
 (0)