Coder Social home page Coder Social logo

Comments (6)

jonathanong avatar jonathanong commented on May 18, 2024

HAHAHA i figured it out. basically, we've got

try {
  ret.value.call(ctx, next);
} catch (e) {
  setImmediate(function(){
    next(e);
  })
}

but because next(e) itself throws if there's no done defined, it'll be recaught and re-thrown at gen.next(throw). the solution is that we always have to do setImmediate(function() {next(e)}).

try {
  ret.value.call(ctx, function(){
    var args = arguments;
    setImmediate(function(){
      next.apply(ctx, args);
    })
  })
} catch (err) {
  setImmediate(function(){
    next(err);
  })
}

however, i feel like this will still fail on the following case since we don't check that next is called twice:

co(function* () {
  yield function (done) {
    done(new Error())
    throw new Error()
  }
})

@visionmedia are you okay with adding setImmediate usage? it's either that or tell people never to yield synchronous functions, which isn't always obvious like yielding a generator. we could also use process.nextTick when available for performance.

from co.

jonathanong avatar jonathanong commented on May 18, 2024

hi, can you check that this branch works? maybe add a few test cases: #50

from co.

vkurchatkin avatar vkurchatkin commented on May 18, 2024

Yep, everything looks ok. Good job!

from co.

jonathanong avatar jonathanong commented on May 18, 2024

okay the PRs are merged. can you check that it works properly in master?

from co.

vkurchatkin avatar vkurchatkin commented on May 18, 2024

Everything seems to work.

from co.

yyrdl avatar yyrdl commented on May 18, 2024

you can check if it is necessary to setImmediate. In other words ,you can check if the func after yield is
asynchronous.

from co.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.