Wednesday, November 8, 2023
HomeiOS Developmentios - Timer that polls is doubling-up (synchronize?)

ios – Timer that polls is doubling-up (synchronize?)


I’ve a Timer that fires each second, and in that code, it makes an API name. Typically the API name takes longer than a second, and it appears to be doubling up on the polling by getting again into it earlier than the earlier one completes. As soon as it will get into that state, the invalidate name does not appear to work, and the polling goes nuts. Is there a easy strategy to deal with one thing like this, to mainly “synchronize” the code in that Process for a given Timer? I clearly do not need to merely improve the timeInterval, as the problem might at all times re-surface regardless.

var pollingTimer: Timer?

pollingTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
    Process {
        await self.makeApiCall()
    }
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments