generator-laravel icon indicating copy to clipboard operation
generator-laravel copied to clipboard

.stdout.on() being called multiple times

Open drbroad opened this issue 11 years ago • 0 comments

Disclaimer: I am no expert with many of the technologies involved, but I have a pretty good handle on concepts. With that out of the way...

I have your generator installed, and I am also using it as inpiration for some of my own generators. I started having errors within my sub-generators with race conditions on async();

Long story short: The event listeners for the stream outputs are being set and called multiple times:

  composer.stdout.on('data', function () {
    self.info(chalk.green('Composer has been found'));
    self.composer = true;
    cb();
  });

and:

    composer.stdout.on('data', function (data) {
      self.info(chalk.green('composer: ') + (data.toString().replace(/\n/g, '')));
    });

So within your generator the first event listener is being called a second time, and in turn, the async is being called again. Within your generator it isnt a problem - the install is the last in the list. Within my sub generator its causing the main generator to fire back up early and call the callback twice. It took me a while to track down this as the problem - helped me learn a lot about how everything links together!

Suggestion

Changing these readouts to composer.stdout.once() will not hold a reference to the listener further down the chain.

(this doesnt have a direct effect on your generator, but it may help you or others further down the line)

Thanks!

drbroad avatar Mar 25 '14 19:03 drbroad