UNPKG

awv3

Version:
33 lines (29 loc) 1.21 kB
// A wrapper around session.request intented to be used with multiRunner as x => commandRunner(session, x) export default function commandRunner(session, commands) { var promise = session.request(commands).then(function (response) { if (response.errors.filter(function (e) { return e.errorState > 1; }).length) throw response.errors[0]; var resultMap = new Map(); for (var _iterator = response.results, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { if (_i >= _iterator.length) break; _ref = _iterator[_i++]; } else { _i = _iterator.next(); if (_i.done) break; _ref = _i.value; } var _result = _ref; if (!resultMap.has(_result.hint)) resultMap.set(_result.hint, []); resultMap.get(_result.hint).push(_result.result); } return resultMap; }); return commands.map(function (command) { return promise.then(function (resultMap) { return resultMap.has(command.task) ? resultMap.get(command.task).shift() : Promise.reject(new Error('Missing result for ' + command.task)); }); }); }