kaminaly / gulp-sync

28 stars 6 forks source link

Synced tasks not waiting for complete finish before continuing #7

Open Sawtaytoes opened 9 years ago

Sawtaytoes commented 9 years ago

If I do a delete, then a write, sometimes the write errors because the file being written is also being deleted at the same time.

Example:

gulp.task('html.rebuild', $.synchronize.sync([
    'html.clean',
    'html.build'
]));

In this example, clean removes the file and build will create the file. Clean is finishing up at the time build runs. It doesn't always happen, but it happens enough to be bothersome; especially when I run a bunch of async synced tasks at once.

kaminaly commented 9 years ago

can i see your html.clean task code?

Sawtaytoes commented 9 years ago
gulp.src(src)
  .pipe($.newer(dest))
  .pipe($.using({prefix: 'html.build', color: 'yellow'}))
  .pipe($.debug({title: 'html.build'}))
  .pipe(gulp.dest(dest))
kaminaly commented 9 years ago

ok, maybe I've got it. I use gulp sync feature for the gulp-sync. so you have to fit in gulp's sync rule.

you can choose from 2 way below.

return Stream

gulp.task('html.clean', function(){
  return gulp.src(src)
    .pipe($.newer(dest))
    .pipe($.using({prefix: 'html.build', color: 'yellow'}))
    .pipe($.debug({title: 'html.build'}))
    .pipe(gulp.dest(dest));
});

do callback

gulp.task('html.clean', function(callback){
  gulp.src(src)
    .pipe($.newer(dest))
    .pipe($.using({prefix: 'html.build', color: 'yellow'}))
    .pipe($.debug({title: 'html.build'}))
    .pipe(gulp.dest(dest))
    .on('end', function(){
      callback();
    });
});

if you choose do callback, you have to care about error handling. sometimes, it stops due to a gulp plugin error. some plugins don't implement enough about error and end event.

Sawtaytoes commented 8 years ago

Returning the stream didn't fix it, but I could try the callback method and see if that helps.