Node.js 使用grunt,如何同时运行三个阻塞任务?

Node.js 使用grunt,如何同时运行三个阻塞任务?,node.js,gruntjs,Node.js,Gruntjs,我已经成功地将grunt contrib watch与grunt nodemon结合使用grunt concurrent,以允许我在编辑和传输coffeescript文件时自动启动node.js实例 下面是GrunFile的grunt concurrent部分,我使用它来实现这一点: gruntile.咖啡 concurrent: dev: tasks: [ 'watch' 'nodemon' ] options: logConc

我已经成功地将
grunt contrib watch
grunt nodemon
结合使用
grunt concurrent
,以允许我在编辑和传输coffeescript文件时自动启动node.js实例

下面是GrunFile的
grunt concurrent
部分,我使用它来实现这一点:

gruntile.咖啡

concurrent:
  dev:
    tasks: [
      'watch'
      'nodemon'
    ]
    options: 
      logConcurrentOutput: true
watch
nodemon
任务在同一个文件中配置,但为了简洁起见已被删除。这工作做得很好

现在我想在并发任务列表中添加一个
grunt节点检查器
。像这样:

concurrent:
  dev:
    tasks: [
      'watch'
      'nodemon'
      'node-inspector'
    ]
    options: 
      logConcurrentOutput: true
至少根据
grunt nodemon
帮助文件,这应该是可能的,因为这是一个示例用法:

然而,这对我不起作用。相反,只启动前两个任务

实验表明,
grunt concurrent
似乎仅限于同时运行两个任务。任何后续任务都将被忽略。我尝试过各种选择,例如:

concurrent:
  dev1:[
      'watch'
      'nodemon'
    ]
  dev2:[
      'node-inspector'
    ]        
    options: 
      logConcurrentOutput: true

grunt.registerTask 'default', ['concurrent:dev1', 'concurrent:dev2']
我还尝试将
限制设置为3。我对此寄予厚望,因此可能我误解了如何正确应用该值:

concurrent:
  dev:
    limit: 3
    tasks: [
      'watch'
      'nodemon'
      'node-inspector'
    ]
    options: 
      logConcurrentOutput: true
但我无法运行第三个阻塞任务

问题 如何使所有三个阻塞任务同时运行


谢谢。

我一直在使用grunt.util.spawn来运行我的任务,并在最后包含了1个阻塞调用。

这个街区的孩子们都死了

var children = [];

process.on('SIGINT', function(){
    children.forEach(function(child) {
        console.log('killing child!');
        child.kill('SIGINT');
    });
});

module.exports = function (grunt) {
    'use strict';

然后我注册一个任务

grunt.registerTask('blocked', 'blocking calls', function() {
    var path = require('path')
    var bootstrapDir = path.resolve(process.cwd()) + '/bootstrap';
    var curDir = path.resolve(process.cwd());

    children.push(
        grunt.util.spawn( {
            cmd: 'grunt',
            args: ['watch'],
            opts: {
                cwd: bootstrapDir,
                stdio: 'inherit',
            }
        })
    );

    children.push(
        grunt.util.spawn( {
            cmd: 'grunt',
            args: ['nodemon'],
            opts: {
                cwd: curDir,
                stdio: 'inherit',
            }
        })
    );

    children.push(
        grunt.util.spawn( {
            cmd: 'grunt',
            args: ['node-inspector'],
            opts: {
                cwd: curDir,
                stdio: 'inherit',
            }
        })
    );

    grunt.task.run('watch');
});

在您的情况下,可以将当前工作目录更改为gruntfile.js并运行多个实例。

将限制值放入选项中,如下所示:

concurrent: {
    tasks: ['nodemon', 'watch', 'node-inspector'],
    options: {
        limit: 5,
        logConcurrentOutput: true
    }
}

我想你读了,你指定了一个限制吗?如果不是,您是否使用双核或多核设置来假装它只是一个?如果是,则发现问题。
dev1
上的打字错误已修复。我尝试了
limit
选项,但没有效果,现在也加入了该示例。谢谢,谢谢,这很有魅力。我还必须设置
限制:4
,以便运行三个任务。