alestane

Resource retreival

Aug 19th, 2011
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.64 KB | None | 0 0
  1. local path = yourBaseRemoteURL
  2.  
  3. local init = coroutine.create(
  4.     function(items, downloader)
  5.         local total = #items
  6.         local item = table.remove(items)
  7.         while item do
  8.             network.download(path..item, "GET", downloader, item)
  9.         end
  10.         repeat
  11.             table.insert(coroutine.yield())
  12.         until items[#total]
  13.         -- process collected resources
  14.     end
  15. )
  16.  
  17. local function downloadProcessor(outcome)
  18.     if outcome.isError then
  19.         local item = outcome.response
  20.         network.download(path..item, "GET", downloadProcessor, item)
  21.     else
  22.         coroutine.resume(init, event.response)
  23.     end
  24. end
  25.  
  26. assert(coroutine.resume(init, {"file1.json", "file2.html"}, downloadProcessor))
Advertisement
Add Comment
Please, Sign In to add comment