Skip to content

Commit

Permalink
sdjournal: adds an async follower method
Browse files Browse the repository at this point in the history
this allows consumers to asynchronously recieve values from systemd
  • Loading branch information
faiq committed Apr 14, 2016
1 parent 7b2428f commit 1271e42
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sdjournal/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,29 @@ process:
return
}

func (r *JournalReader) FollowAsync(until <-chan time.Time, recieve chan<- []byte) <-chan error {
errCh := make(chan error, 1)
go func() {
var msg = make([]byte, 64*1<<(10))
for {
c, err := r.Read(msg)
if err != nil && err != io.EOF {
errCh <- err
}
select {
case <-until:
errCh <- nil
return
default:
if c > 0 {
recieve <- msg[:c]
}
}
}
}()
return errCh
}

// buildMessage returns a string representing the current journal entry in a simple format which
// includes the entry timestamp and MESSAGE field.
func (r *JournalReader) buildMessage() (string, error) {
Expand Down

0 comments on commit 1271e42

Please sign in to comment.