ios - PromiseKit implement cache and fetch feature -


i trying implement caching layer extension promisekit. can fetch data cache->doaction , refreshdata network calls->doaction. 1 of solutions found below:-

func fetch() -> promise<data, promise<data>> { return promise { fulfill, reject in     let fresh = urlsession.get(url)     let cache = data(contentsoffile: cachepath)     fulfill((cache, fresh))   } }  fetch().then { cacheddata, freshdata -> promise<data> in   if let data = cacheddata {     update(data: data)    }   return freshdata }.then(execute: update) 

is there better way solve problem?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -