Directed Broadcast in Combine

Hi everybody.

I'm looking for a way to use a passthrough as a directed broadcast, I mean, when I code a sink over this subject I want to receive only the values that match with an identifier.

like this.

let id = "whatever"
passthroughSubjectItem.sink(for: id, receiveValue:  {
  print(value.description)
}

let element = Element(id: "id" , other: "Other")
passthroughSubjectItem.send(element)

let element2 = Element(id: "whatever" , other: "Other")
passthroughSubjectItem.send(element2)

Console result expected:

id = "whatever", other = "Other"

In the same way if I code a subject with an error I want to achieve that this error could go directed to the subscriber for X id.

I mean, if I get an error downloading x item even retrying it, I want to advise to the subscriber with a completion failure, but only for the subscriber that is pointing to this item id.

Thanks in advance

If you want a sink to only receive values that satisfy some condition, then just apply the filter operator before the sink.

1 Like