Git Product home page Git Product logo

Comments (6)

popomore avatar popomore commented on May 30, 2024

You can add dep when define a task.

g.task('copy', ['clean'], function() {

});

from gulp.

phated avatar phated commented on May 30, 2024

Tasks run with maximum concurrency.

What you actually want is:

var g = require('gulp');
var util = require('util');

g.task('clean', function(cb) {
  setTimeout(function() {
    util.log('clean task executed.');
    cb(null);
  }, 3000);
});

g.task('copy', ['clean'], function(cb) {
  util.log('copy task executed.');
  cb();
});

g.task('default', ['clean', 'copy'], function() {
  util.log('default task executed.');
});

Notice the only change is making copy depend on clean

from gulp.

robrich avatar robrich commented on May 30, 2024

I agree, the docs need work here. By default, the tasks run with maximum concurrency -- e.g. it launches all the tasks at once and waits for nothing. If you want to create a series where tasks run in a particular order, you need to do two things: give it a hint to tell it when the task is done, and give it a hint that a task depends on completion of another.

For these examples, let's presume you have two tasks, "one" and "two" that you specifically want to run in this order:

  1. In task "one" you add a hint to tell it when the task is done. Either take in a callback and call it when you're done or return a promise or stream that the engine should wait to resolve or end respectively.
  2. In task "two" you add a hint telling the engine that it depends on completion of the first task.

So this example would look like this:

var gulp = require('gulp');

// takes in a callback so the engine knows when it'll be done
gulp.task('one', function (cb) {
    // do stuff -- async or otherwise
    cb(err); // if you pass non-null, non-undefined, gulp will stop, and note that the build failed
});

// identifies a dependent task must be complete before this one begins
gulp.task('two', ['one'], function () {
    // task 'one' is done now
});

from gulp.

monbro avatar monbro commented on May 30, 2024

thank you robrich, that was what I was looking for

from gulp.

tomek-he-him avatar tomek-he-him commented on May 30, 2024

Just a quick note:

When doing things in a stream, this seems to work great for me:

gulp.task('do-stuff', function (done) {
    gulp.src(someFiles)
        .pipe(doStuffToThem())
        .on('end', function () { done(); });
});

from gulp.

gwildu avatar gwildu commented on May 30, 2024

I guess there is no way to use on the task, that has a dependency the returned stream of that dependency?

from gulp.

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.