LINUX.ORG.RU

История изменений

Исправление x3al, (текущая версия) :

var suspend = require('suspend');

suspend(function*(resume) {
  first = yield slowProcedure(10, 20, resume);
  if(first[0]) throw first[0];
  second = yield slowProcedure(30, 40, resume);
  if(second[0]) throw second[0];
  console.log(first[1] + second[1]);
})();

Исходная версия x3al, :

Вот так твой код в ОП может выглядеть, если slowProcedure возвращает результат в node-style коллбэке

var suspend = require('suspend');

suspend(function*(resume) {
  first = yield slowProcedure(10, 20, resume);
  if(first[0]) throw first[0];
  second = yield slowProcedure(30, 40, resume);
  if(second[0]) throw second[0];
  console.log(first[1] + second[1]);
})()