Добавить murom.getMany и murom.import
This commit is contained in:
67
api/2019-09-10.js
Normal file
67
api/2019-09-10.js
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user