Skip to content

Commit

Permalink
Merge 8e32ecb into ff7e5e8
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Feb 17, 2015
2 parents ff7e5e8 + 8e32ecb commit 2ccd584
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 160 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# dist
dist/

# ignore dependencies
node_modules/

Expand Down
16 changes: 13 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ cache:
notifications:
email: false
after_success:
- npm run coveralls
- npm run coveralls
env:
global:
- COVERALLS_SERVICE_NAME="travis-ci"
- secure: "JylUwHCc/uOqpVg4EffIdCKfInzHbJYza1+YOtPeJruyumfV/pekxh2NRgtxal957Vre3csw5mj0I0hbkvsX9zTL/sYEQXbhyfFxx0A5ZT5y5tSDjn6pHmEUJ+We4ozReE7MlmFYaf5/n7y1o9VkTM71lgsTIcYi0ausmGhHlrg="
- COVERALLS_SERVICE_NAME="travis-ci"
- secure: JylUwHCc/uOqpVg4EffIdCKfInzHbJYza1+YOtPeJruyumfV/pekxh2NRgtxal957Vre3csw5mj0I0hbkvsX9zTL/sYEQXbhyfFxx0A5ZT5y5tSDjn6pHmEUJ+We4ozReE7MlmFYaf5/n7y1o9VkTM71lgsTIcYi0ausmGhHlrg=
- secure: A6Ynw+P64hSVxuQpf3UbszrA17FuvvOwS9158PsxslXhsO5NfocZta3hiEc5pAOxO64G1g9RY7Qgod6bEF2p3I5w2OeqAGgZ5pQKTpyTFqogG1iPMjbQsfU5cofD5GiWC4zJ51yj1H3HyJo7f4urNH5fVLrLxmXpAemWtj2GmpI=
deploy:
provider: npm
email: npm@christophwitzko.com
skip_cleanup: true
api_key:
secure: UadcitgfhkGyojPHeLm3OjcUR7b3rNtOc7jTW78ehaIXNndYZx/teBnShCIqI+k4GxbJbHMvjkOB8dLB96BhtTnS2uWhxP6epi7m8iA90aN2PXfD8cnBRu1B2cu+F/d0/mwvXCL+hvL5Dfs4FSZ5r6ImFVwU/XiB0sfe7BmbMHg=
on:
branch: master
repo: christophwitzko/parallizer
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# parallizer
# Parallizer
[![Travis](https://img.shields.io/travis/christophwitzko/parallizer.svg?style=flat)](https://travis-ci.org/christophwitzko/parallizer) [![Coveralls](https://img.shields.io/coveralls/christophwitzko/parallizer.svg?style=flat)](https://coveralls.io/r/christophwitzko/parallizer?branch=master) [![Code Climate](https://img.shields.io/codeclimate/github/christophwitzko/parallizer.svg?style=flat)](https://codeclimate.com/github/christophwitzko/parallizer) [![npm](https://img.shields.io/npm/v/parallizer.svg?style=flat)](https://www.npmjs.com/package/parallizer) [![npm](https://img.shields.io/npm/dm/parallizer.svg?style=flat)](https://www.npmjs.com/package/parallizer) [![Packagist](https://img.shields.io/packagist/l/doctrine/orm.svg?style=flat)](https://github.com/christophwitzko/parallizer/raw/master/LICENSE)
> Parallizer is a tool that makes working with asynchronous functions much easier.
Expand All @@ -9,11 +9,11 @@
## Example

```js
var parallizer = require('parallizer')
var Parallizer = require('parallizer')

// creates a new Parallel object
// creates a new Parallizer object
// that will only run 3 functions at the same time.
var prl = new parallizer.Parallel(3)
var prl = new Parallizer(3)

// very important: last argument must be the callback.
var add2 = function (id, rnd, cb) {
Expand All @@ -31,9 +31,9 @@ for (var i = 0; i < 100; i++) {

## Documentation

### new parallizer.Parallel([max], [cb], [paused])
### new Parallizer([max], [cb], [paused])

Creates an new Parallel object.
Creates an new Parallizer object.

**Arguments**

Expand All @@ -43,7 +43,7 @@ Creates an new Parallel object.

---------------------

### parallel.sadd(fn[, arg1[, arg2[, ...]]])
### parallizer.sadd(fn[, arg1[, arg2[, ...]]])

Adds a function to the queue an executes it if possible.

Expand All @@ -54,9 +54,9 @@ Adds a function to the queue an executes it if possible.

---------------------

### parallel.add(fn, [args], [cb], [scope], [high])
### parallizer.add(fn, [args], [cb], [scope], [high])

This function does the same like `parallel.sadd`, but with a different API.
This function does the same like `parallizer.sadd`, but with a different API.

**Arguments**

Expand All @@ -68,13 +68,13 @@ This function does the same like `parallel.sadd`, but with a different API.

---------------------

### parallel.start()
### parallizer.start()

Starts the paused queue.

---------------------

### parallel.pause()
### parallizer.pause()

Pauses the queue.

Expand Down
4 changes: 2 additions & 2 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html>
<head>
<title>parallizer</title>
<script type="text/javascript" src="parallizer.js"></script>
<script type="text/javascript" src="dist/parallizer.js"></script>
<script type="text/javascript">
var prl = new parallizer.Parallel(3);
var prl = new Parallizer(3);

var add2 = function(id, rnd, cb){
setTimeout(function(){
Expand Down
4 changes: 2 additions & 2 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var parallizer = require('./parallizer.js')
var Parallizer = require('./')

var files = [
'http://nodejs.org/dist/v0.10.28/node-v0.10.28-darwin-x64.tar.gz',
Expand All @@ -19,7 +19,7 @@ function downloadFile (url, dest, cb) {
setTimeout(cb, 2000) // simulate downloading
}

var prl = new parallizer.Parallel(1, function () {
var prl = new Parallizer(1, function () {
console.log('done.')
})

Expand Down
65 changes: 65 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict'

var callbackCount = require('callback-count')
var nextTick = require('next-tick')

function Parallizer (max, col, paused) {
if (!(this instanceof Parallizer)) return new Parallizer(max, col, paused)
var pm = parseInt(max, 10)
this._max = (!isNaN(pm) && pm > 0) ? pm : 1
this._running = 0
this._queue = []
this._paused = !!paused
this._col = null
if (typeof col === 'function') {
this._col = callbackCount(nextTick.apply.bind(nextTick, null, [col]))
}
}

Parallizer.prototype.add = function (fn, args, cb, scope, high) {
var self = this
if (!(args instanceof Array)) args = []
if (typeof cb !== 'function') cb = function () {}
args.push(function () {
cb.apply(this, Array.prototype.slice.call(arguments))
if (self._col) self._col.next()
self._running--
self._check()
})
fn = (typeof fn === 'function') ? fn : function () {}
var fno = fn.apply.bind(fn, scope || null, args || [])
self._queue[high ? 'unshift' : 'push'](fno)
if (self._col) self._col.inc()
self._check()
}

Parallizer.prototype.sadd = function () {
var fa = Array.prototype.slice.call(arguments)
if (fa.length > 0) {
var fn = fa.shift()
var cb = function () {}
if (fa.length > 0 && typeof fa[fa.length - 1] === 'function') cb = fa.pop()
this.add(fn, fa, cb)
}
}

Parallizer.prototype._check = function () {
if (!this._paused && this._running < this._max && this._queue.length > 0) {
this._running++
nextTick(this._queue.shift())
}
}

Parallizer.prototype.pause = function () {
this._paused = true
}

Parallizer.prototype.start = function () {
this._paused = false
this._check()
}

// backwards compatibility
Parallizer.Parallel = Parallizer

module.exports = Parallizer
28 changes: 21 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "parallizer",
"version": "1.2.1",
"version": "0.0.0-semantically-released",
"description": "asynchronous functions helper",
"author": "Christoph Witzko <npm@christophwitzko.com> (http://christophwitzko.com/)",
"main": "parallizer.js",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/christophwitzko/parallizer.git"
Expand All @@ -13,17 +13,22 @@
"mocha": "mocha --require should --reporter spec --check-leaks",
"coverage": "mocha --require blanket --require should --reporter html-cov > coverage.html",
"coveralls": "mocha --require blanket --require should --reporter mocha-lcov-reporter | coveralls",
"prepublish": "semantic-release pre",
"browserify": "browserify index.js --standalone Parallizer -o dist/parallizer.js",
"minify": "uglifyjs dist/parallizer.js -o dist/parallizer.min.js",
"build": "rm -rf dist && mkdir dist && npm run browserify && npm run minify",
"prepublish": "npm run build && semantic-release pre",
"postpublish": "semantic-release post"
},
"devDependencies": {
"blanket": "^1.1.6",
"browserify": "^8.1.3",
"coveralls": "^2.11.2",
"mocha": "^2.1.0",
"mocha-lcov-reporter": "0.0.1",
"semantic-release": "^3.0.2",
"should": "^4.4.2",
"standard": "*"
"should": "^5.0.0",
"standard": "*",
"uglify-js": "^2.4.16"
},
"engines": {
"iojs": "^1",
Expand All @@ -46,8 +51,17 @@
},
"config": {
"blanket": {
"pattern": "parallizer.js"
"pattern": "parallizer/index.js"
}
},
"homepage": "https://github.com/christophwitzko/parallizer"
"homepage": "https://github.com/christophwitzko/parallizer",
"dependencies": {
"callback-count": "^0.1.0",
"next-tick": "^0.2.2"
},
"standard": {
"ignore": [
"dist/**"
]
}
}
97 changes: 0 additions & 97 deletions parallizer.js

This file was deleted.

26 changes: 0 additions & 26 deletions test/Collector.js

This file was deleted.

Loading

0 comments on commit 2ccd584

Please sign in to comment.