let newPhotos = photos.selectedPhotos
.filter { $0.size.width > $0.size.height }
.prefix(while: { [unowned self] _ in
return self.images.value.count < 6
})
.share()
newPhotos
.map { [unowned self] newImage in
// 1
return self.images.value + [newImage]
}
// 2
.assign(to: \.value, on: images)
// 3
.store(in: &subscriptions)
newPhotos
.ignoreOutput()
.delay(for: 2.0, scheduler: DispatchQueue.main)
.sink(receiveCompletion: { [unowned self] _ in
self.updateUI(photos: self.images.value)
}, receiveValue: { _ in })
.store(in: &subscriptions)
newPhotos
.filter { [unowned self] _ in
return self.images.value.count == 5
}
.flatMap { [unowned self] _ in
self.alert(title: "Reach limit", text: "You have reached your limit")
}
.sink(receiveValue: { [unowned self] in
self.navigationController?.popViewController(animated: true)
})
.store(in: &subscriptions)
From the code above, newPhotos
is a share publisher. There are 3 subscriptions afterwards. My questions is that is there a guarantee which subscriptions will be called first since the first subscription will increase the images value count which the 3rd subscription rely on that value to display alert.
How do we make sure one runs before another and keep the subscriptions separate