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

Allow a nested inline subtask in the new syntax #61

Open
satazor opened this issue Jun 25, 2013 · 2 comments
Open

Allow a nested inline subtask in the new syntax #61

satazor opened this issue Jun 25, 2013 · 2 comments

Comments

@satazor
Copy link
Member

satazor commented Jun 25, 2013

The new syntax does allow inline nested subtasks. While this is not common, it's desirable in some cases. Before we could do something like:

var myTask = {
    name: 'my-task',
    tasks: [
    {
        name: 'inline-task',
        tasks: [
            // ...
        ]
    }
    ]
}

I suggest something like:

module.exports = function (task) {
    task
    .name('my-task')
    .do(function (options, ctx, next) {
        var inlineTask = ctx.task()
        .name('inline-task')
        .do(/** ... */)
        .do(/** ... */;

        next(null, inlineTask);
    });
};

This even allows to create a inline task asynchronously.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@oleics
Copy link

oleics commented Jul 1, 2013

Hi @satazor

over the weekend I spent some time thinking about how to define automaton-tasks and some other things related to automaton.

About subtasks.. what about this:

moulde.exports = function(task) {
  task
    .id('task-a')
    // "task-a" executes "task-b"
    .do('task-b')
  // Explicitly end "task-a" and start with a new one:
  .end()
    // Define "task-b"
    .id('task-b')
    .do(function(options, ctx, next) { next(); })
  ;
};

This way, the definition of a task is strictly separated from the execution of a task.
(which makes cutting out subtasks into module-files for later code-sharing an easy job.)

Another pattern is:

moulde.exports = function(task) {
  task
    .id('task-a')
    // Define "task-b" explicitly as a subtask of "task-a"
    .subtask(function(task) {
      task
        .id('task-b')
        .do(function(options, ctx, next) { next(); })
      // Lets define another subtask of "task-a"
      .end()
        .id('task-c')
        .do(function(options, ctx, next) { next(); })
      ;
    })
    //.subtask(require('./bad-habit'))
    // Execute a subtask of "task-a"
    .do('task-a task-b')
    .do('task-a task-c --foo bar') // (Use 'shell-quote'.parse and run the result through 'optimist')
  ;
};

Again, a strict separation between task-definition and task-execution.

Both approaches keep things readable.

Additionally, let tasks invoke automaton.run and maybe provide var inlineTask = automaton.task('task-id'). But only "maybe", as it introduces more nesting.

@marcooliveira
Copy link
Member

I see what you're trying to do there @oleics, but I think you can already do it by simply storing the inline tasks in some var and use that var when do()'ing. If you later on need to move the "subtask" to another file, you just copy the function and require() it.

What we're discussing here is the ability to declare tasks inline, and in runtime. I think the syntax looks good, but I'm wondering if this might be overkill. Haven't seen anything requiring this yet.

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

No branches or pull requests

3 participants