generator

by Artem

JavaScript

'use strict';

function doRequest(url) {
  return fetch(url).then(res => res.json());
}

function* test() {
  let res = yield doRequest('https://httpbin.org/ip');
  console.log('res was returned from external code');
  return res;
}

const generator = test();
generator.next().value.then(r => console.log(generator.next(r).value));