async-iterator-close.js 581 B

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