[Bug 25923] isTypeSupported should be asynchronous

https://www.w3.org/Bugs/Public/show_bug.cgi?id=25923

--- Comment #6 from Domenic Denicola <domenic@domenicdenicola.com> ---
Promises work best in collaboration with other ES6 features. So the example
code becomes much simpler and easier to read in that case:

Promise.all([iTS("system1", "webm"), iTS("system1", "cenc"), iTS("system2",
"webm"), ...]).then(
  ([webm1, cenc1, webm2, ...]) => {
    if (webm1) {
      [keySystem, mediaType] = ["system1", "webm"];
    } else if (cenc1) {
      [keySystem, mediaType] = ["system1", "cenc"];
    } else if ...
    ...
  });
});

Of course I would imagine most programmers would abstract this:

var combos = [["system1", "webm"], ["system1", "cenc"], ["system2", "webm"]];

Promise.all(combos.map(combo => iTS(...combo))).then(results => {
  for (var i = 0; i < results.length; ++i) {
    if (results[i]) {
      [keySystem, mediaType] = combos[i];
      break;
    }
  }
});

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Sunday, 1 June 2014 05:48:32 UTC