You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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:
I suggest something like:
This even allows to create a inline task asynchronously.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: