async-iterator-close.js 567 B

123456789101112131415161718
  1. var call = require('../internals/function-call');
  2. var getBuiltIn = require('../internals/get-built-in');
  3. var getMethod = require('../internals/get-method');
  4. module.exports = function (iterator, method, argument, reject) {
  5. try {
  6. var returnMethod = getMethod(iterator, 'return');
  7. if (returnMethod) {
  8. return getBuiltIn('Promise').resolve(call(returnMethod, iterator)).then(function () {
  9. method(argument);
  10. }, function (error) {
  11. reject(error);
  12. });
  13. }
  14. } catch (error2) {
  15. return reject(error2);
  16. } method(argument);
  17. };