Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.定义一个异步任务,后面的任务依赖这个异步任务 #3

Open
zhufengnodejs opened this issue Jan 27, 2016 · 18 comments

Comments

@zhufengnodejs
Copy link
Owner

No description provided.

@zhufengnodejs
Copy link
Owner Author

var a = 10;

@Brolly0204
Copy link

var aa=0;
gulp.task("one",function(){
    console.log(1);
});
gulp.task("two",function(cd){
   setTimeout(function(){
        console.log(2);
        aa+=3;
        cd();
    },3000)
});
gulp.task("three",function(){
    console.log(3);
    aa+=3
});
gulp.task("default",["one","two","three"],function(){
    console.log(aa)
});
Mr.Li@PC-Li MINGW64 /d/gulpstudy
$ gulp default
[15:46:23] Using gulpfile D:\gulpstudy\gulpfile.js
[15:46:23] Starting 'one'...
1
[15:46:23] Finished 'one' after 788 μs
[15:46:23] Starting 'two'...
[15:46:23] Starting 'three'...
3
[15:46:23] Finished 'three' after 102 μs
2
[15:46:26] Finished 'two' after 3 s
[15:46:26] Starting 'default'...
6
[15:46:26] Finished 'default' after 84 μs

@zhangguiping2015
Copy link

var aaa=10;
gulp.task("1",function(){
    return gulp.src('src/index.html').pipe(gulp.dest('disk'))
    console.log("我是先执行的");
})
gulp.task("2",function(cb){
    setTimeout(function(){
        return gulp.src('src/index.doc').pipe(gulp.dest('disk'))
        console.log("我这个定时器最后执行");
        cb();
    },3000)
})
gulp.task("3",function(){
    return gulp.src('src/index.txt').pipe(gulp.dest('disk'))
    console.log("我是第二个执行的");
})
gulp.task("default",["1","2","3"],function(){
    console.log("我是第三个执行的"+aaa);
})

@Liuyundere
Copy link

gulp.task("html",function(){
    return gulp.src("history/1.html").pipe(gulp.dest("dist"));
});
gulp.task("js",function(){
    setTimeout(function(){
        return gulp.src("history/1.js").pipe(gulp.dest("dist"));
    },3000);
});
gulp.task("less",function(){
    return gulp.src("history/1.less").pipe(gulp.dest("dist"));
});


gulp.task("default",["html","js","less"]);

@qiujinlong11
Copy link

gulp.task("one",function(){
    setTimeout(function(){
        console.log('one is done')
    },3000);
});
gulp.task("two",["one"],function(){
    console.log('two is done')
});
gulp.task("3",function(){
    console.log('3 is done')
});

gulp.task("default",["one","two","3"],function(){
    console.log("232321")
})

@renjinhui
Copy link

#任金辉

var gulp=require("gulp");
var abc=10;
gulp.task("1",function(){
    console.log(1);
});

gulp.task("2",function(cb){
    setTimeout(function(){
        console.log(2);
        abc++;
        cb();
    },2000)

});

gulp.task("3",function(){
    console.log(3);
});

gulp.task("CP-html",function(){
    return gulp.src("*.json").pipe(gulp.dest("dist"));
});

gulp.task("default",["1","2","3","CP-html"],function(){
    console.log(abc);
});

@liuying0525
Copy link

gulp.task("one",function(){
    gulp.src("src/a.js").pipe(gulp.dest("list/foo.js/temp"))
});

gulp.task("two",function(ed){
    setTimeout(function(){
        gulp.src("src/*/*.js").pipe(gulp.dest("list/foo.js/temp"));
        ed();
    },3000);
});

gulp.task("three",function(){
    gulp.src("src/**/*.js").pipe(gulp.dest("list/foo.js/temp"))
});

gulp.task("default",["one","two","three"]);
[15:51:14] Using gulpfile d:\gulpstudy\gulpfile.js
[15:51:14] Starting 'one'...
[15:51:14] Finished 'one' after 7.87 ms
[15:51:14] Starting 'two'...
[15:51:14] Starting 'three'...
[15:51:14] Finished 'three' after 3.01 ms
[15:51:17] Finished 'two' after 3 s
[15:51:17] Starting 'default'...
[15:51:17] Finished 'default' after 8.29 μs

@da-panggui
Copy link

var a=10;
gulp.task("1",function(){
    console.log("1")
});

gulp.task("2",function(bc){
    setTimeout(function(){
        a+=20;
        console.log("2");
        bc();
    },2000)

});
gulp.task("3",function(){
    console.log("3")
});

gulp.task("default",["1","2","3"],function(){
   console.log(a)
});

@luoaihua919
Copy link

var aa=10;
gulp.task('one',function(){
    console.log(1);
});
gulp.task('two',function(cb){
    setTimeout(function(){
        gulp.src('src/*.js').pipe(gulp.dest('desk'));
        console.log(2);
        aa++;
        cb();
    },3000);
});
gulp.task('three',function(){
    gulp.src('src/index.html').pipe(gulp.dest('desk'));
    aa+=2;
});
gulp.task('default',['one','two','three'],function(){
    console.log(aa);
});

@wangxiaobo718
Copy link

var aaa=10;
var gulp=require("gulp");

gulp.task("1",function(){
    console.log("1")
});
gulp.task("2",function(){
    console.log("2")
});
gulp.task("3",function(){
    console.log("3")
    aaa+=3
});
gulp.task("default",["1","2","3"],function(){
    console.log(aaa);
});

@lomo1314
Copy link

var aaa=10;
var gulp = require("gulp");

gulp.task('1', function () {
    console.log('1')
})
gulp.task('2', function () {
    console.log('2');
})

gulp.task('3', function () {
    console.log('3');
    aaa+=3
})

gulp.task("default",['1','2','3'], function () {
    console.log(aaa);
})

@yuhongtao1
Copy link

var gulp=require("gulp");
gulp.task("ok",function(){
    setTimeout(function(){
        console.log("jhuhuhu");
    },5000);
});
gulp.task("default",["ok"],function(){
    console.log("default")
});
gulp.task("copy",["ok"],function(){
    return gulp.src("data.txt").pipe(gulp.dest("duration"))
});

gulp.task("default",["copy","ok"]);

@ghost
Copy link

ghost commented Jan 27, 2016

var gulp = require('gulp');
var sum = 0;
gulp.task('default', ['one', 'two'], function () {
    console.log(sum);
});

gulp.task('one', function (callBack) {
    setTimeout(function () {
        sum += 1;
        console.log(sum);
        callBack();
    }, 2000);
});

gulp.task('two', function () {
    sum += 2;
    console.log(sum);
});

@cjleung
Copy link

cjleung commented Jan 27, 2016

 // 第一个参数是任务的名字
    var gulp = require('gulp');

// 第二个参数是本任务
    /*
    gulp.task('任务名', function(){
        // 就是把gulp笔记.html 拷贝一份到 dist 这个目录里去一份
        gulp.src('src/gulp笔记.html').pipe(gulp.dest('dist'));
    });
    */
    gulp.task('html', function(){
        gulp.src('src/index.html').pipe(gulp.dest('dist'));
    });

    gulp.task('css', function(){
        gulp.src('src/css.css').pipe(gulp.dest('dist'));
    });

    gulp.task('javascript', function(){
        gulp.src('src/javascript.js').pipe(gulp.dest('dist'));
    });

    gulp.task('NodeJs', function(){
        gulp.src('src/NodeJs.js').pipe(gulp.dest('dist'));
    });

    gulp.task("default",["html","css","javascript","NodeJs"],function(){
        console.log("拷贝完成....100%");
    });
F:\gulplop>gulp default
[16:03:24] Using gulpfile F:\gulplop\gulpfile.js
[16:03:24] Starting 'html'...
[16:03:24] Finished 'html' after 10 ms
[16:03:24] Starting 'css'...
[16:03:24] Finished 'css' after 15 ms
[16:03:24] Starting 'javascript'...
[16:03:24] Finished 'javascript' after 1.27 ms
[16:03:24] Starting 'NodeJs'...
[16:03:24] Finished 'NodeJs' after 715 μs                                                                                                                                                     
[16:03:24] Starting 'default'...
拷贝完成....100%                                                                                                                                                                               
[16:03:24] Finished 'default' after 260 μs  

@wangmengyuan
Copy link

var gulp = require('gulp');
var num = 0;
gulp.task("one", function () {
    console.log("one");
});
gulp.task("two", function (a) {
    setTimeout(function () {
        console.log("two");
        num += 1;
        a();
    }, 3000)
});
gulp.task("three", function () {
    console.log("three");
    num += 3
});
gulp.task("default", ["one", "two", "three"], function () {
    console.log(num)
});

@yuzhi000
Copy link

var gulp= require("gulp");
gulp.task("1",function(){
    setTimeout(function(){
        console.log('最后')
    },3000);
});
gulp.task("2",function(){
    console.log('two is done 第一')
});
gulp.task("3",function(){
    console.log('3 is done 第二')
});
gulp.task("4",["2"],function(){
    console.log('4 is done 第三')
});

gulp.task("default",["1","2","3","4"],function(){
    console.log("哈哈 第四")
});

@wangwensha
Copy link

var aa=0;
gulp.task("one",function(){
    console.log(1);
});
gulp.task("two",['one'],function(cd){
    setTimeout(function(){
        console.log("2");
        aa+=3;
        cd();
    },3000)
});
gulp.task("three",function(){
    console.log(3);
    aa+=3
});
gulp.task("default",["two","three"],function(){
    console.log(aa)
});

@niuxiaoxin123
Copy link

var a=10;
gulp.task('1',function(){
    console.log('1');
    a=3;
})
gulp.task('2',function(){
    setTimeout(function(){
        console.log('1122');
        a+=5;
    },3000)
})
gulp.task('3',function(){
    console.log('3');
    a++;
})
gulp.task('default',['1','2','3'],function(){
    console.log(a);
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests