ObserveEndOfFile implemented

This commit is contained in:
milarin
2024-01-10 21:56:00 +01:00
parent 4b0dd8e5a6
commit 82652060a7
2 changed files with 30 additions and 6 deletions

View File

@ -7,6 +7,18 @@ import (
"git.milar.in/milarin/channel"
)
func ObserveEndOfFile(ctx context.Context, socket string) (<-chan string, error) {
ch, err := ObserveEvent[any](ctx, socket, "end-file")
if err != nil {
return nil, err
}
getReason := func(e Event[any]) string { return e.Reason }
notEmpty := func(str string) bool { return str != "" }
reasons := channel.Filter(channel.MapSuccessive(ch, getReason), notEmpty)
return reasons, nil
}
func ObserveDisplayNames(ctx context.Context, socket string) (<-chan []string, error) {
return ObserveProperty[[]string](ctx, socket, "display-names")
}