Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send an error to a PassthroughSubject?

Tags:

swift

combine

let myPassthrough = PassthroughSubject<String, Error>()

I know I can send a value to a passthrough subject using send:

myPassthrough.send("abc")

How do I send a failure?


I tried:

myPassthrough.send(Fail(error: error))
myPassthrough.send(completion: Fail(error: error))
myPassthrough.send(completion: Just(error))
myPassthrough.send(completion: error)

None of them compile

like image 415
Senseful Avatar asked Jul 18 '20 18:07

Senseful


People also ask

What is a passthroughsubject?

A subject that broadcasts elements to downstream subscribers. As a concrete implementation of Subject, the PassthroughSubject provides a convenient way to adapt existing imperative code to the Combine model.

What is passthroughsubject in Salesforce combine?

As a concrete implementation of Subject, the PassthroughSubject provides a convenient way to adapt existing imperative code to the Combine model. Unlike CurrentValueSubject, a PassthroughSubject doesn’t have an initial value or a buffer of the most recently-published element.

Can I use a delegate pattern instead of a passthroughsubject?

PassthroughSubjectcan easily be used in place of a delegate pattern, or to convert an existing delegate pattern to Combine.

Can we send serialized events on a concurrent dispatchqueue?

We are now able to satisfy the constraint of 1.03 even if the DispatchQueue is concurrent or the OperationQueue is not a restriction of maxConcurrentOperations of 1, or for that matter any valid scheduler being concurrent; we will always send serialized events on that requested scheduler for .receive (on:).


1 Answers

Looks like Subscribers.Completion is an enum, so this works:

myPassthrough.send(completion: .failure(error))
like image 81
Senseful Avatar answered Sep 21 '22 10:09

Senseful