Дополнения к МУРОМУ | MUROM additions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.3KB

  1. // Subscribe several functions in a single call.
  2. Reporter.prototype.subscribeMany = function(funcs)
  3. {
  4. for (var i = 0; i < funcs.length; ++i)
  5. {
  6. var func = funcs[i];
  7. this.subscribe(func);
  8. }
  9. }
  10. murom.getMany = function(items, completionCallback)
  11. {
  12. var self = this;
  13. var results = {};
  14. var count = 0;
  15. function reportCompletion()
  16. {
  17. if (++count == items.length)
  18. {
  19. if (completionCallback)
  20. {
  21. completionCallback(results);
  22. }
  23. }
  24. }
  25. for (var id in items)
  26. {
  27. const item = items[id];
  28. const url = item[0];
  29. const name = item[1];
  30. var isBinary = (item[2] == "b");
  31. function success(contents)
  32. {
  33. results[name] = contents;
  34. reportCompletion()
  35. }
  36. function failure(status)
  37. {
  38. LOG(
  39. formatString(
  40. "ERROR Could not download URL: '{0}' status: '{1}'",
  41. url,
  42. status
  43. )
  44. );
  45. reportCompletion()
  46. }
  47. if (isBinary)
  48. {
  49. murom.getb(url, success, failure);
  50. }
  51. else
  52. {
  53. murom.get(url, success, failure);
  54. }
  55. }
  56. };