瀏覽代碼

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

master
父節點
當前提交
66816d0a83
共有 1 個文件被更改,包括 67 次插入0 次删除
  1. +67
    -0
      api/2019-09-10.js

+ 67
- 0
api/2019-09-10.js 查看文件

@@ -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…
取消
儲存