Browse Source

Добавить murom.getMany и murom.import

master
parent
commit
66816d0a83
1 changed files with 67 additions and 0 deletions
  1. +67
    -0
      api/2019-09-10.js

+ 67
- 0
api/2019-09-10.js View File

@@ -0,0 +1,67 @@

// Subscribe several functions in a single call.
Reporter.prototype.subscribeMany = function(funcs)
{
for (var i = 0; i < funcs.length; ++i)
{
var func = funcs[i];
this.subscribe(func);
}
}

murom.getMany = function(urls, completionCallback)
{
var self = this;
var results = new Array(urls.length).fill(null);

var count = 0;
function reportCompletion()
{
if (++count == urls.length)
{
if (completionCallback)
{
completionCallback(results);
}
}
}
for (var id in urls)
{
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)
{
for (var id in contents)
{
eval(contents[id]);
}
}
);
};

Loading…
Cancel
Save