I have scenario where threads calling the same method which is having timer, for each thread timer will be different because thread created in different timeline based on the action from the UI. How can I get the timer value for each thread separately in single view and single init of the class, though I tried to get the different response but for dynamic creation of threads its not responsive, below one I am just trying on playground
var groupqueue = DispatchGroup()
private var update: [AnyCancellable] = []
var ticker: Int = 0
groupqueue.enter()
multiplecall(name: "test1")
groupqueue.enter()
multiplecall(name: "test2")
func multiplecall(name: String){
Timer.publish(every: 1, on: .main, in: .common)
.autoconnect()
.sink { _ in fetchValues() }
.store(in: &update)
}
func fetchValues(){
ticker += 1
print(ticker)
}
required output : 1 1, 2 2, 3 3...\n
what I am getting: 1,2,3,4...