Gulp“完成了什么”方法呢? [英] What does Gulp "done" method do?

查看:101
本文介绍了Gulp“完成了什么”方法呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个简单的问题来澄清参数done在gulp任务中做了什么?



I理解,这是任务函数中的回调,如下所示。

  gulp.task('clean',function(done){ 
//所以一些东西
creategulptask(cleantask(),done);
});

但是通过它的原因是什么?

解决方案

gulp文档指定了类似于以下的内容:

  var gulp =要求( '吞'); 

//进行回调以便引擎知道何时完成
//此回调由Gulp传入 - 它们不是参数/参数
//为你的任务。
gulp.task('one',function(cb){
//做东西 - 异步或其他
//如果err不为null并且未定义,则此任务将停止,
//并注意它失败
cb(err);
});

//标识一个​​依赖任务必须在这个任务开始之前完成
gulp.task('two',['one'],function(){
// Task '一'现在完成,这将现在运行...
});

gulp.task('default',['one','two']);

done参数被传递到用于定义任务的回调函数中。

你的任务函数可以接受回调函数参数(通常这个函数参数被命名为 done )。执行 done完成函数告诉Gulp任务完成时提示它。



Gulp需要这个提示您是否要订购 系列的相互依赖的任务,如上例所示。 (即任务两个)将不会开始,直到任务一个调用 cb())从本质上讲,如果你不想让它们同时运行,它将停止并发运行。



你可以在这里阅读更多关于它的信息: https://github.com/gulpjs/gulp/blob/master /docs/API.md#async-task-support


Just a simple question to clarify what does parameter "done" in a gulp task do?

I understand, this is the callback in task function as shown below.

gulp.task('clean', function(done) {
    // so some stuff
    creategulptask(cleantask(), done);
});

But what is the reason to pass it?

解决方案

The gulp documentation specifies something similar to the following:

var gulp = require('gulp');

// Takes in a callback so the engine knows when it'll be done
// This callback is passed in by Gulp - they are not arguments / parameters
// for your task.
gulp.task('one', function(cb) {
    // Do stuff -- async or otherwise
    // If err is not null and not undefined, then this task will stop, 
    // and note that it failed
    cb(err); 
});

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

gulp.task('default', ['one', 'two']);

The done argument is passed into the callback function you use to define your tasks.

Your task function can "accept a callback" function parameter (often this function parameter is named done). Executing that done function tells Gulp "a hint to tell it when the task is done".

Gulp needs this hint if you want to order a series of tasks that depend on each other, as shown in the above example. (i.e. task two won't begin until task one calls cb()) In essence, it stops tasks from running concurrently if you don't want them to.

You can read more about this here: https://github.com/gulpjs/gulp/blob/master/docs/API.md#async-task-support

这篇关于Gulp“完成了什么”方法呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆