Files
Nanaloveyuki 25a6a973d2 πŸ“ Update More API Document
2026-05-20 11:37:49 +08:00

1.8 KiB

name, group, category, update-time, description, key-word
name group category update-time description key-word
split-sink api sink 20260520 Create a sink that routes records to one of two sinks using a predicate.
sink
split
routing
public

Split-sink

Create a sink that routes each record to one of two sinks based on a predicate. This helper is useful for target-based or policy-based sink routing.

Interface

pub fn[A, B] split_sink(left : A, right : B, predicate : (Record) -> Bool) -> SplitSink[A, B] {

input

  • left : A - Sink receiving records when the predicate returns true.
  • right : B - Sink receiving records when the predicate returns false.
  • predicate : (Record) -> Bool - Routing function evaluated for each record.

output

  • SplitSink[A, B] - Conditional routing sink.

Explanation

Detailed rules explaining key parameters and behaviors

  • The predicate decides which side receives each record.
  • Unlike fanout_sink(...), a record is routed to one side only.
  • This helper is useful for target-aware and content-aware routing policies.

How to Use

Here are some specific examples provided.

When Need Predicate-based Routing

When audit records should go to a different destination:

let sink = split_sink(console_sink(), json_console_sink(), fn(rec) {
  rec.target == "audit"
})

In this example, only records matching the predicate go to the left sink.

Error Case

e.g.:

  • If both destinations should always receive the same record, use fanout_sink(...) instead.

  • Predicate logic is caller-defined, so misrouting comes from predicate choice rather than sink mechanics.

Notes

  1. This helper is a routing primitive for synchronous sink composition.

  2. split_by_level(...) is a convenience wrapper for level-based routing.