разница между вызовом пре-промежуточного программного обеспечения со следующим и без следующего - PullRequest
0 голосов
/ 28 апреля 2020

Я не хочу знать, в чем разница между вызовом промежуточного программного обеспечения со следующим и без следующего

Пример без следующего Все промежуточное программное обеспечение прекрасно работает без следующего также

tourSchema.pre('save', function () {
  console.log('second middleware is getting called');
  const currentDoc = this;
  const slugDocument = slugify(currentDoc.name, { lower: true });
  this.slug = slugDocument;
  console.log('after addition of slug', this);
});
tourSchema.pre('save', function () {
  console.log('third pre middleware is called');
});
tourSchema.pre('save', function () {
  console.log('4th middleware is getting called');
});

со следующим там Кажется, нет разницы с вызовом следующего или без следующего. Так в чем же главное различие между этими двумя?

tourSchema.pre('save', function (next) {
  console.log('second middleware is getting called');
  const currentDoc = this;
  const slugDocument = slugify(currentDoc.name, { lower: true });
  this.slug = slugDocument;
  console.log('after addition of slug', this);
  next();
});
tourSchema.pre('save', function (next) {
  console.log('third pre middleware is called');
  next();
});
tourSchema.pre('save', function (next) {
  console.log('4th middleware is getting called');
  next();
});
...