improved code coverage

This commit is contained in:
2024-08-22 17:07:42 +01:00
parent 4093f1893a
commit f4321c6261
2 changed files with 27 additions and 16 deletions

View File

@@ -1,8 +1,7 @@
package gubgub
// Forever wrapper makes it more explicit that a subscriber will never stop consuming messages.
// This helps avoiding subscribers that always return true which, depending on their size, might
// not be immediately clear.
// This helps avoiding subscribers that always return TRUE.
func Forever[T any](fn func(T)) Subscriber[T] {
return func(msg T) bool {
fn(msg)
@@ -10,7 +9,17 @@ func Forever[T any](fn func(T)) Subscriber[T] {
}
}
// NoOp creates a subscriber that does absolutely nothing forever. This is mostly useful for testing.
// Once returns a subscriber that will consume only one message.
// This helps avoiding subscribers that always return FALSE.
func Once[T any](fn func(T)) Subscriber[T] {
return func(t T) bool {
fn(t)
return false
}
}
// NoOp creates a subscriber that does absolutely nothing forever.
// This is mostly useful for testing.
func NoOp[T any]() Subscriber[T] {
return func(_ T) bool { return true }
}