I have one publisher let subject = PassthroughSubject<Human,Error>()
that emits the following objects,
subject.send(Human(fName: "John", lName: "Abraham"))
subject.send(Human(fName: "Jane", lName: "Anne"))
I need there to be a delay between these two objects, when they are being received.
example(of: "delayy(with:)"){
struct Human {
let fName: String
let lName: String
}
let subject = PassthroughSubject<Human,Error>()
let delayInSeconds = 4
var isLoading = false
subject
.delay(for: .seconds(delayInSeconds), scheduler: DispatchQueue.main)
subject.sink(
receiveCompletion:{
print("Received Completion", $0)
isLoading = true
print("isLoading =", isLoading)
},
receiveValue: {
print("Value Received:" ,$0)
})
subject.send(Human(fName: "John", lName: "Abraham"))
subject.send(Human(fName: "Jane", lName: "Anne"))
subject.send(completion: .finished)
}
The First value the publisher is going to be emitting here is (fName: "John", lName: "Abraham")
. The second value emitted is going to be (fName: "Jane", lName: "Anne")
.
I want there to be a delay between these two objects when the values are received here in print("Value Received:" ,$0)
I tried adding delay but it does not seem to be working. Any help is appreciated. (I am a beginner to combine)
fyi: The above code snippet is from playground