ios - How to check when app has 'come to rest' when waiting on a long series of data processing and network related callbacks -


i'm doing large-scale data read apple health respository. reading several kinds of data. each kind of data requesting data sources time doing source query sources per data type , doing data query time per source data type.

when data retrieved, aggregate algorithmically , upload results of aggregation remote server sync user's account data across devices.

the result of structure is

per source (1) query callback returns list of sources (2) each source, query returns data each source, in callback (3) in last callback, data processed , made ready upload. when upload completed, there final callback

i can't know timing or number of queries. have noted healthkit callbacks not returned ( think it's underlying sqlite db stopping responding/timing out connections?).

so how can know or guess when process over? i'd find way know app has 'come rest' mean there no disk read/writes , no network activity going on anymore. what's way that, say, check app activity in last 30 seconds , if there has been no network or read/write activity, declares process 'finished' , makes ui available again?

create singleton class tracks number of outstanding queries. when new request starts, tell increment counter (either atomic increment or performing work using dispatch_sync onto main thread if isn't running there). when each request ends, tell singleton class decrement counter.

if there dependent resource requests (e.g. if requesting resource tells app needs fetch resource b , resource c), sure start subsequent requests (or @ least enqueue them start) in way increments counter in singleton class before decrement counter on original resource.

in singleton class, block ui (if that's necessary) loading screen whenever value goes 0 nonzero, , unblock (hiding loading screen) when goes 0 again.


Comments