Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- elseif parsedPath.type == "web" then
- -- append the download to the queue
- self.downloadQueue = self.downloadQueue:next(function()
- -- create our download promise for async reaction
- local downloadPromise = Promise.new()
- -- throttle downloads to to 1 per 100ms
- network.http.client(parsedPath.host, 80):wait(50, function() end):get(parsedPath.path, function(res)
- if res.status == 200 then
- -- construct an understandable moduleAddress for our error messages
- local moduleAddress = fullPath
- if(moduleAddress:len() > 48) then
- moduleAddress = "..." .. moduleAddress:sub(moduleAddress:len() - 45)
- end
- -- parse the content
- local loader, err = load(res.body, moduleAddress)
- if err then
- self.registry[fullPath] = {success = false, result = err}
- else
- self.registry[fullPath] = {success = true, result = Module(fullPath, loader)}
- end
- -- return our promise
- return self.registry[fullPath].success and downloadPromise:resolve(self.registry[fullPath].result) or downloadPromise:reject(self.registry[fullPath].result)
- else
- downloadPromise:reject("error " .. res.status .. " while retrieving script from \"" .. fullPath .. "\":\n" .. res.body)
- end
- end)
- -- resolve promise chain
- return downloadPromise:next(function(module) promise:resolve(module) end, function(err) promise:reject(err) end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement