Skip to content

Commit

Permalink
v3.3.0. Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Nov 1, 2013
1 parent 742b4b4 commit b83899b
Show file tree
Hide file tree
Showing 13 changed files with 300 additions and 1,059 deletions.
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,4 +1,4 @@
# v1.3.0 October 26, 2013 # v1.3.5 October 31, 2013
# https://github.com/bevry/base # https://github.com/bevry/base


# Temp Files # Temp Files
Expand All @@ -8,4 +8,5 @@
build/ build/
components/ components/
bower_components/ bower_components/
node_modules/ node_modules/
out/
8 changes: 6 additions & 2 deletions Cakefile
@@ -1,4 +1,4 @@
# v1.3.1 October 26, 2013 # v1.3.4 October 30, 2013
# https://github.com/bevry/base # https://github.com/bevry/base




Expand Down Expand Up @@ -138,7 +138,11 @@ actions =
# npm publish # npm publish
spawn(NPM, ['publish'], {stdio:'inherit', cwd:APP_DIR}).on 'close', safe next, -> spawn(NPM, ['publish'], {stdio:'inherit', cwd:APP_DIR}).on 'close', safe next, ->
# git tag # git tag
spawn(GIT, ['tag', 'v'+PACKAGE_DATA.version, '-a'], {stdio:'inherit', cwd:APP_DIR}).on('close', safe next) spawn(GIT, ['tag', 'v'+PACKAGE_DATA.version, '-a'], {stdio:'inherit', cwd:APP_DIR}).on 'close', safe next, ->
# git push origin master
spawn(GIT, ['push', 'origin', 'master'], {stdio:'inherit', cwd:APP_DIR}).on 'close', safe next, ->
# git push tags
spawn(GIT, ['push', 'origin', '--tags'], {stdio:'inherit', cwd:APP_DIR}).on('close', safe next)




# ===================================== # =====================================
Expand Down
6 changes: 6 additions & 0 deletions History.md
@@ -1,5 +1,11 @@
## History ## History


- v3.3.0 November 1, 2013
- Bindings are now more explicit
- Improved configuration parsing
- Configuration is now accessed via `getConfig()`
- Dropped component.io and bower support, just use ender or browserify

- v3.2.4 October 27, 2013 - v3.2.4 October 27, 2013
- Re-packaged - Re-packaged


Expand Down
3 changes: 2 additions & 1 deletion LICENSE.md
Expand Up @@ -3,7 +3,8 @@


# License # License


Copyright &copy; Benjamin Lupton <b@lupton.cc> Copyright &copy; 2013+ Bevry Pty Ltd <us@bevry.me> (http://bevry.me)
<br/>Copyright &copy; 2011-2012 Benjamin Lupton <b@lupton.cc> (http://balupton.com)


## The MIT License ## The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Expand Down
138 changes: 98 additions & 40 deletions README.md
Expand Up @@ -9,10 +9,10 @@
<!-- BADGES/ --> <!-- BADGES/ -->


[![Build Status](http://img.shields.io/travis-ci/bevry/taskgroup.png?branch=master)](http://travis-ci.org/bevry/taskgroup "Check this project's build status on TravisCI") [![Build Status](http://img.shields.io/travis-ci/bevry/taskgroup.png?branch=master)](http://travis-ci.org/bevry/taskgroup "Check this project's build status on TravisCI")
[![NPM version](https://badge.fury.io/js/taskgroup.png)](https://npmjs.org/package/taskgroup "View this project on NPM") [![NPM version](http://badge.fury.io/js/taskgroup.png)](https://npmjs.org/package/taskgroup "View this project on NPM")
[![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip") [![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip")
[![Flattr donate button](https://raw.github.com/balupton/flattr-buttons/master/badge-89x18.gif)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr") [![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](https://www.paypalobjects.com/en_AU/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal") [![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")


<!-- /BADGES --> <!-- /BADGES -->


Expand All @@ -36,14 +36,6 @@ Group together synchronous and asynchronous tasks and execute them with support
- Use: `require('taskgroup')` - Use: `require('taskgroup')`
- Install: `ender add taskgroup` - Install: `ender add taskgroup`


### [Component](http://github.com/component/component)
- Use: `require('taskgroup')`
- Install: `component install bevry/taskgroup`

### [Bower](http://bower.io/)
- Use: `require('taskgroup')`
- Install: `bower install taskgroup`

<!-- /INSTALL --> <!-- /INSTALL -->




Expand All @@ -59,7 +51,7 @@ var TaskGroup = require('taskgroup').TaskGroup;
var group = new TaskGroup(); var group = new TaskGroup();


// Define what should happen once the group has completed // Define what should happen once the group has completed
group.once('complete', function(err,results){ group.once('complete', function(err, results){
// Log the error that has occured // Log the error that has occured
console.log(err); console.log(err);
// => null // => null
Expand Down Expand Up @@ -92,7 +84,7 @@ group.addTask(function(){
}); });


// Add a sub-group to our exiting group // Add a sub-group to our exiting group
group.addGroup(function(addGroup,addTask){ group.addGroup(function(addGroup, addTask){
// Tell this sub-group to execute in parallel (all at once) by setting its concurrency to unlimited // Tell this sub-group to execute in parallel (all at once) by setting its concurrency to unlimited
// by default the concurrency for all groups is set to 1 // by default the concurrency for all groups is set to 1
// which means that they execute in serial fashion (one after the other, instead of all at once) // which means that they execute in serial fashion (one after the other, instead of all at once)
Expand Down Expand Up @@ -122,10 +114,12 @@ new (require('taskgroup')).TaskGroup()
``` ```


- Available methods: - Available methods:
- `constructor(name?,fn?)` - create our new group, the arguments `name` and `fn` are optional, refer to their entries in configuration - `constructor(name?,fn?)` - create our new group, arguments can be a String for `name`, an Object for `config`, and a Function for `next`
- `setConfig(config)` - set the configuration for the group, returns chain - `setConfig(config)` - set the configuration for the group, returns chain
- `addTask(args...)` - create a new task item with the arguments and adds it to the group, returns the new task item - `getconfig()` - return the set configuration
- `addGroup(args...)` - create a new group item with the arguments and adds it to the group, returns the new group item - `addTask(args...)`, `addTasks(tasks, args..)` - create a new task item with the arguments and adds it to the group, returns the new task item(s)
- `addGroup(args...)`, `addGroups(groups, args..)` - create a new group item with the arguments and adds it to the group, returns the new group item(s)
- `addItem(item)`, `addItem(items)` - adds the items to the group, returns the item(s)
- `getTotals()` - returns counts for the following `{running,remaining,completed,total}` - `getTotals()` - returns counts for the following `{running,remaining,completed,total}`
- `clear()` - remove the remaining items to be executed - `clear()` - remove the remaining items to be executed
- `pause()` - pause the execution of the items - `pause()` - pause the execution of the items
Expand All @@ -136,10 +130,14 @@ new (require('taskgroup')).TaskGroup()
- All those of [EventEmitter2](https://github.com/hij1nx/EventEmitter2) - All those of [EventEmitter2](https://github.com/hij1nx/EventEmitter2)
- Available configuration: - Available configuration:
- `name`, no default - allows us to assign a name to the group, useful for debugging - `name`, no default - allows us to assign a name to the group, useful for debugging
- `fn(addGroup,addTask,complete?)`, no default - allows us to use an inline and self-executing style for defining groups, useful for nesting - `method(addGroup, addTask, complete?)`, no default - allows us to use an inline and self-executing style for defining groups, useful for nesting
- `concurrency`, defaults to `1` - how many items shall we allow to be run at the same time, set to `0` to allow unlimited - `concurrency`, defaults to `1` - how many items shall we allow to be run at the same time, set to `0` to allow unlimited
- `pauseOnError`, defaults to `true` - if an error occurs in one of our items, should we stop executing any remaining items? - `pauseOnError`, defaults to `true` - if an error occurs in one of our items, should we stop executing any remaining items?
- setting to `false` will continue with execution with the other items even if an item experiences an error - setting to `false` will continue with execution with the other items even if an item experiences an error
- `items` - alias for `.addTasks(items)`
- `groups` - alias for `.addGroups(groups)`
- `tasks` - alias for `.addTasks(tasks)`
- `next` - alias for `.once('complete', next)`
- Available events: - Available events:
- `run()` - fired just before we execute the items - `run()` - fired just before we execute the items
- `complete(err, results)` - fired when all our items have completed - `complete(err, results)` - fired when all our items have completed
Expand All @@ -158,20 +156,21 @@ new (require('taskgroup')).Task()
``` ```


- Available methods: - Available methods:
- `constructor(name?,fn?)` - create our new task, the arguments `name` and `fn` are optional though `fn` must be set at some point, refer to their entries in configuration - `constructor(args...)` - create our new task, arguments can be a String for `name`, an Object for `config`, and a Function for `next`
- `setConfig(config)` - set the configuration for the group, returns chain - `setConfig(config)` - set the configuration for the group, returns chain
- `getconfig()` - return the set configuration
- `complete()` - will fire the completion event if we are already complete, useful if you're binding your listeners after run - `complete()` - will fire the completion event if we are already complete, useful if you're binding your listeners after run
- `run()` - execute the task - `run()` - execute the task
- Available configuration: - Available configuration:
- `name`, no default - allows us to assign a name to the group, useful for debugging - `name`, no default - allows us to assign a name to the group, useful for debugging
- `fn(complete?)`, no default - must be set at some point, it is the function to execute for the task, if it is asynchronous it should use the completion callback provided - `method(complete?)`, no default - must be set at some point, it is the function to execute for the task, if it is asynchronous it should use the completion callback provided
- `args`, no default - an array of arguments that you would like to precede the completion callback when executing `fn` - `args`, no default - an array of arguments that you would like to precede the completion callback when executing `fn`
- `next` - alias for `.once('complete', next)`
- Available events: - Available events:
- `run()` - fired just before we execute the task - `run()` - fired just before we execute the task
- `complete(err, args...)` - fired when the task has completed - `complete(err, args...)` - fired when the task has completed





## Comparison with [Async.js](https://github.com/caolan/async) ## Comparison with [Async.js](https://github.com/caolan/async)


The biggest advantage and difference of TaskGroup over async.js is that TaskGroup has one uniform API to rule them all, whereas with async.js I found that I was always having to keep referring to the async manual to try and figure out which is the right call for my use case then somehow wrap my head around the async.js way of doing things (which more often than not I couldn't), whereas with TaskGroup I never have that problem as it is one consistent API for all the different use cases. The biggest advantage and difference of TaskGroup over async.js is that TaskGroup has one uniform API to rule them all, whereas with async.js I found that I was always having to keep referring to the async manual to try and figure out which is the right call for my use case then somehow wrap my head around the async.js way of doing things (which more often than not I couldn't), whereas with TaskGroup I never have that problem as it is one consistent API for all the different use cases.
Expand All @@ -189,10 +188,13 @@ async.series([
], next); ], next);


// TaskGroup // TaskGroup
new TaskGroup().once('complete', next) new TaskGroup({
.addTask(function(){}) tasks: [
.addTask(function(callback){callback();}) function(){},
.run(); function(callback){callback();}
],
next: next
}).run();




// ==================================== // ====================================
Expand All @@ -205,11 +207,14 @@ async.parallel([
], next); ], next);


// TaskGroup // TaskGroup
new TaskGroup().setConfig({concurrency:0}).once('complete', next) new TaskGroup({
.addTask(function(){}) concurrency: 0,
.addTask(function(callback){callback();}) tasks: [
.run(); function(){},

function(callback){callback();}
],
next: next
}).run();


// ==================================== // ====================================
// Map // Map
Expand All @@ -218,25 +223,78 @@ new TaskGroup().setConfig({concurrency:0}).once('complete', next)
async.map(['file1','file2','file3'], fs.stat, next); async.map(['file1','file2','file3'], fs.stat, next);


// TaskGroup // TaskGroup
var tasks = new TaskGroup().setConfig({concurrency:0}).once('complete', next); new TaskGroup({
['file1','file2','file3'].forEach(function(file){ concurrency: 0,
tasks.addTask(function(complete){ tasks: ['file1', 'file2', 'file3'].map(function(file){
fs.stat(file,complete); return function(complete){
}); fs.stat(file, complete);
}); }
tasks.run(); }),
next: next
}).run();
``` ```


Another big advantage of TaskGroup over async.js is TaskGroup's ability to add tasks to the group once execution has already started - this is a common use case when creating an application that must perform it's actions serially, so using TaskGroup you can create a serial TaskGroup for the application, run it right away, then add the actions to the group as tasks. Another big advantage of TaskGroup over async.js is TaskGroup's ability to add tasks to the group once execution has already started - this is a common use case when creating an application that must perform it's actions serially, so using TaskGroup you can create a serial TaskGroup for the application, run it right away, then add the actions to the group as tasks.


A final big advantage of TaskGroup over async.js is TaskGroup's ability to do nested groups, this allowed us to created the [Joe Testing Framework & Runner](https://github.com/bevry/joe) incredibly easily, and because of this functionality Joe will always know which test (task) is associated to which suite (task group), whereas test runners like mocha have to guess (they add the task to the last group, which may not always be the case! especially with dynamically created tests!). A final big advantage of TaskGroup over async.js is TaskGroup's ability to do nested groups, this allowed us to created the [Joe Testing Framework & Runner](https://github.com/bevry/joe) incredibly easily, and because of this functionality Joe will always know which test (task) is associated to which suite (task group), whereas test runners like mocha have to guess (they add the task to the last group, which may not always be the case! especially with dynamically created tests!).




<!-- HISTORY/ -->

## History ## History
You can discover the history inside the [History.md](https://github.com/bevry/taskgroup/blob/master/History.md#files) file [Discover the change history by heading on over to the `History.md` file.](https://github.com/bevry/taskgroup/blob/master/History.md#files)

<!-- /HISTORY -->


<!-- CONTRIBUTE/ -->

## Contribute

[Discover how you can contribute by heading on over to the `Contributing.md` file.](https://github.com/bevry/taskgroup/blob/master/Contributing.md#files)

<!-- /CONTRIBUTE -->


<!-- BACKERS/ -->

## Backers


### Maintainers

These amazing people are maintaining this project:

- Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)

### Sponsors

No sponsors yet! Will you be the first?

[![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/bevry/ "Donate weekly to this project using Gittip")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")

### Contributors

These amazing people have contributed code to this project:

- Benjamin Lupton <b@lupton.cc> (https://github.com/balupton) - [view contributions](https://github.com/bevry/taskgroup/commits?author=balupton)
- sfrdmn (https://github.com/sfrdmn) - [view contributions](https://github.com/bevry/taskgroup/commits?author=sfrdmn)

[Become a contributor!](https://github.com/bevry/taskgroup/blob/master/Contributing.md#files)

<!-- /BACKERS -->


<!-- LICENSE/ -->


## License ## License
Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://creativecommons.org/licenses/MIT/)
<br/>Copyright © 2013+ [Bevry Pty Ltd](http://bevry.me) Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT license](http://creativecommons.org/licenses/MIT/)
<br/>Copyright © 2011-2012 [Benjamin Arthur Lupton](http://balupton.com)
Copyright &copy; 2013+ Bevry Pty Ltd <us@bevry.me> (http://bevry.me)
<br/>Copyright &copy; 2011-2012 Benjamin Lupton <b@lupton.cc> (http://balupton.com)

<!-- /LICENSE -->


37 changes: 0 additions & 37 deletions bower.json

This file was deleted.

27 changes: 0 additions & 27 deletions component.json

This file was deleted.

20 changes: 12 additions & 8 deletions cyclic.js
@@ -1,9 +1,13 @@
// v1.3.0 October 26, 2013 // v1.3.7 November 1, 2013
// https://github.com/bevry/base // https://github.com/bevry/base
if ( require('fs').existsSync('.git') ) { (function(){
require('child_process').spawn( var fsUtil = require('fs'),
process.platform.indexOf('win') === 0 ? process.execPath.replace('node.exe', 'npm.cmd') : 'npm', name = require('./package.json').name;
['install', '--force', require('./package.json').name], if ( fsUtil.existsSync('.git') === true && fsUtil.existsSync('./node_modules/'+name) === false ) {
{env:process.env, cwd:process.cwd(), stdio:'inherit'} require('child_process').spawn(
).on('error', console.log).on('close', console.log); process.platform.indexOf('win') === 0 ? process.execPath.replace('node.exe', 'npm.cmd') : 'npm',
} ['install', '--force', name],
{env:process.env, cwd:process.cwd(), stdio:'inherit'}
).on('error', console.log).on('close', console.log);
}
})()

0 comments on commit b83899b

Please sign in to comment.