Hi I have a case where I need to call the same method in multiple Tasks. I want to have a possibility to call this method one by one (sync) not in parallel mode. It looks like that:
var isReadyToRefresh: Bool = true
func refresh(value: Int) async {
try! await Task.sleep(nanoseconds: 100_000_000) // imitation API CALL
isReadyToRefresh = false
print("Try to refresh: \(value)")
}
func mockCallAPI(value: Int) async {
if isReadyToRefresh {
await refresh(value: value)
}
}
Task {
await mockCallAPI(value: 1)
}
Task {
await mockCallAPI(value: 2)
}
output:
Try to refresh: 1
Try to refresh: 2
my required output:
Try to refresh: 1 OR Try to refresh 2. Depends which task has been called as first one.
Any ideas?