Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FatalOnError ¶
func FatalOnError[T any]() func(ro.Observable[T]) ro.Observable[T]
Play: https://go.dev/play/p/LuG085GGvvh
Example ¶
br := bufio.NewWriter(os.Stdout) log.SetOutput(br) log.SetFlags(0) defer br.Flush() // FatalOnError passes items through when no error occurs. // When an error is received, it calls log.Fatal (which exits the program). observable := ro.Pipe1( ro.Just(1, 2, 3), FatalOnError[int](), ) subscription := observable.Subscribe(ro.NoopObserver[int]()) defer subscription.Unsubscribe()
func FatalOnErrorWithPrefix ¶
func FatalOnErrorWithPrefix[T any](prefix string) func(ro.Observable[T]) ro.Observable[T]
Play: https://go.dev/play/p/9E0dtrSJrxE
Example ¶
br := bufio.NewWriter(os.Stdout)
log.SetOutput(br)
log.SetFlags(0)
defer br.Flush()
// FatalOnErrorWithPrefix passes items through when no error occurs.
// When an error is received, it calls log.Fatal with the given prefix.
observable := ro.Pipe1(
ro.Just("a", "b", "c"),
FatalOnErrorWithPrefix[string]("[MyApp]"),
)
subscription := observable.Subscribe(ro.NoopObserver[string]())
defer subscription.Unsubscribe()
func Log ¶
func Log[T any]() func(ro.Observable[T]) ro.Observable[T]
Example ¶
br := bufio.NewWriter(os.Stdout) log.SetOutput(br) log.SetFlags(0) defer br.Flush() // Log all notifications (Next, Error, Complete) observable := ro.Pipe1( ro.Just(1, 2, 3, 4, 5), Log[int](), ) subscription := observable.Subscribe(ro.NoopObserver[int]()) defer subscription.Unsubscribe()
Output: ro.Next: 1 ro.Next: 2 ro.Next: 3 ro.Next: 4 ro.Next: 5 ro.Complete
Example (InPipeline) ¶
br := bufio.NewWriter(os.Stdout)
log.SetOutput(br)
log.SetFlags(0)
defer br.Flush()
// Use logging in a complex pipeline
observable := ro.Pipe3(
ro.Just(1, 2, 3, 4, 5),
ro.Filter(func(n int) bool { return n%2 == 0 }), // Keep even numbers
LogWithPrefix[int]("[Filter]"),
ro.Map(func(n int) string { return fmt.Sprintf("Even: %d", n) }),
)
subscription := observable.Subscribe(ro.NoopObserver[string]())
defer subscription.Unsubscribe()
Output: [Filter] ro.Next: 2 [Filter] ro.Next: 4 [Filter] ro.Complete
Example (WithContext) ¶
br := bufio.NewWriter(os.Stdout)
log.SetOutput(br)
log.SetFlags(0)
defer br.Flush()
// Log with context-aware operations
ctx := context.Background()
observable := ro.Pipe1(
ro.Just("context", "aware", "logging"),
LogWithPrefix[string]("[Context]"),
)
subscription := observable.SubscribeWithContext(ctx, ro.NoopObserver[string]())
defer subscription.Unsubscribe()
Output: [Context] ro.Next: context [Context] ro.Next: aware [Context] ro.Next: logging [Context] ro.Complete
Example (WithError) ¶
br := bufio.NewWriter(os.Stdout)
log.SetOutput(br)
log.SetFlags(0)
defer br.Flush()
// Log including error notifications
observable := ro.Pipe1(
ro.NewObservable(func(observer ro.Observer[int]) ro.Teardown {
observer.Next(1)
observer.Next(2)
observer.Error(errors.New("something went wrong"))
observer.Next(3) // This won't be emitted due to error
return nil
}),
Log[int](),
)
subscription := observable.Subscribe(ro.NoopObserver[int]())
defer subscription.Unsubscribe()
Output: ro.Next: 1 ro.Next: 2 ro.Error: something went wrong
func LogWithPrefix ¶
func LogWithPrefix[T any](prefix string) func(ro.Observable[T]) ro.Observable[T]
Play: https://go.dev/play/p/plP2gfryjzK
Example ¶
br := bufio.NewWriter(os.Stdout)
log.SetOutput(br)
log.SetFlags(0)
defer br.Flush()
// Log with a custom prefix
observable := ro.Pipe1(
ro.Just("hello", "world", "golang"),
LogWithPrefix[string]("[MyApp]"),
)
subscription := observable.Subscribe(ro.NoopObserver[string]())
defer subscription.Unsubscribe()
Output: [MyApp] ro.Next: hello [MyApp] ro.Next: world [MyApp] ro.Next: golang [MyApp] ro.Complete
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.