From 69bbe42d20f74a3f1351e731a5d1384d72fcc817 Mon Sep 17 00:00:00 2001 From: Michael Kapelko Date: Tue, 10 Sep 2019 13:14:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20getMany.=20=D0=A3=D0=B1=D1=80=D0=B0=D1=82=D1=8C=20impo?= =?UTF-8?q?rt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/2019-09-10.js | 72 ++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/api/2019-09-10.js b/api/2019-09-10.js index 1190c18..0e77ab6 100644 --- a/api/2019-09-10.js +++ b/api/2019-09-10.js @@ -9,15 +9,15 @@ Reporter.prototype.subscribeMany = function(funcs) } } -murom.getMany = function(urls, completionCallback) +murom.getMany = function(items, completionCallback) { var self = this; - var results = new Array(urls.length).fill(null); + var results = {}; var count = 0; function reportCompletion() { - if (++count == urls.length) + if (++count == items.length) { if (completionCallback) { @@ -26,43 +26,37 @@ murom.getMany = function(urls, completionCallback) } } - for (var id in urls) + for (var id in items) { - const url = urls[id]; - const urlId = id; - murom.get( - url, - function(contents) - { - results[urlId] = contents; - reportCompletion() - }, - function(status) - { - LOG( - formatString( - "ERROR Could not download URL: '{0}' status: '{1}'", - url, - status - ) - ); - reportCompletion() - } - ); - } -}; - -murom.import = function(urls, completionCallback) -{ - murom.getMany( - urls, - function(contents) + const item = items[id]; + const url = item[0]; + const name = item[1]; + var isBinary = (item[2] == "b"); + + function success(contents) { - for (var id in contents) - { - eval(contents[id]); - } - completionCallback(); + results[name] = contents; + reportCompletion() + } + function failure(status) + { + LOG( + formatString( + "ERROR Could not download URL: '{0}' status: '{1}'", + url, + status + ) + ); + reportCompletion() + } + + if (isBinary) + { + murom.getb(url, success, failure); + } + else + { + murom.get(url, success, failure); } - ); + } };