SHARE
TWEET

Untitled

a guest Oct 12th, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         elseif parsedPath.type == "web" then
  2.             -- append the download to the queue
  3.             self.downloadQueue = self.downloadQueue:next(function()
  4.                 -- create our download promise for async reaction
  5.                 local downloadPromise = Promise.new()
  6.  
  7.                 -- throttle downloads to to 1 per 100ms
  8.                 network.http.client(parsedPath.host, 80):wait(50, function() end):get(parsedPath.path, function(res)
  9.                     if res.status == 200 then
  10.                         -- construct an understandable moduleAddress for our error messages
  11.                         local moduleAddress = fullPath
  12.                         if(moduleAddress:len() > 48) then
  13.                             moduleAddress = "..." .. moduleAddress:sub(moduleAddress:len() - 45)
  14.                         end
  15.  
  16.                         -- parse the content
  17.                         local loader, err = load(res.body, moduleAddress)
  18.                         if err then
  19.                             self.registry[fullPath] = {success = false, result = err}
  20.                         else
  21.                             self.registry[fullPath] = {success = true, result = Module(fullPath, loader)}
  22.                         end
  23.  
  24.                         -- return our promise
  25.                         return self.registry[fullPath].success and downloadPromise:resolve(self.registry[fullPath].result) or downloadPromise:reject(self.registry[fullPath].result)
  26.                     else
  27.                         downloadPromise:reject("error " .. res.status .. " while retrieving script from \"" .. fullPath .. "\":\n" .. res.body)
  28.                     end
  29.                 end)
  30.  
  31.                 -- resolve promise chain
  32.                 return downloadPromise:next(function(module) promise:resolve(module) end, function(err) promise:reject(err) end)
  33.             end)
RAW Paste Data
Top