Comparing version 2.2.1 to 3.0.0
{ | ||
"name": "sequence", | ||
"version": "2.2.1", | ||
"description": "The sequence module of FuturesJS (Ender.JS and Node.JS)", | ||
"homepage": "https://github.com/coolaj86/futures", | ||
"keywords": ["flow-control", "async", "asynchronous", "futures", "sequence", "chain", "step", "util", "browser"], | ||
"version": "3.0.0", | ||
"description": "Execute async code in chronological order. The sequence module of FuturesJS (Browser, Node.js, Bower, and Pakmanager)", | ||
"homepage": "https://github.com/FuturesJS/sequence", | ||
"keywords": ["futuresjs", "flow-control", "async", "asynchronous", "futures", "sequence", "chain", "step", "util", "browser"], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/coolaj86/futures.git" | ||
"url": "git://github.com/FuturesJS/sequence.git" | ||
}, | ||
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)", | ||
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.com)", | ||
"main": "sequence.js", | ||
@@ -13,0 +13,0 @@ "directories": { |
@@ -1,35 +0,78 @@ | ||
sequence() | ||
---- | ||
Sequence | ||
=== | ||
Creates an Asynchronous Stack which execute each enqueued method after the previous function calls the provided `next(err, data [, ...])`. | ||
**Core** | ||
In many cases [`forEachAsync`](https://github.com/FuturesJS/forEachAsync) or [`forAllAsync`](https://github.com/FuturesJS/forAllAsync) will be a better alternative. | ||
* `Futures.sequence(globalContext=null)` | ||
* `then(next, err, data [, ...])` - add a method onto the queue | ||
API | ||
--- | ||
* `Sequence.create(defaultContext=null)` | ||
* `then(function callback(next, err, data [, ...]) {}, context)` - add a callback onto the queue | ||
* begins or resumes the queue | ||
* passes the results of the previous function into the next | ||
**Example:** | ||
Node.js Installation | ||
--- | ||
var sequence = Futures.sequence(), | ||
err; | ||
Node.JS (Server): | ||
sequence | ||
.then(function (next) { | ||
setTimeout(function () { | ||
next(err, "Hi", "World!"); | ||
}, 120); | ||
}) | ||
.then(function (next, err, a, b) { | ||
setTimeout(function () { | ||
next(err, "Hello", b); | ||
}, 270); | ||
}) | ||
.then(function (next, err, a, b) { | ||
setTimeout(function () { | ||
console.log(a, b); | ||
next(); | ||
}, 50); | ||
}); | ||
```bash | ||
npm install sequence | ||
``` | ||
Browser Installation | ||
--- | ||
You can install from bower: | ||
```bash | ||
bower install sequence | ||
``` | ||
Or download the raw file from <https://raw.github.com/FuturesJS/sequence/master/sequence.js>: | ||
```bash | ||
wget https://raw.github.com/FuturesJS/sequence/master/sequence.js | ||
``` | ||
Or build with pakmanager: | ||
```bash | ||
pakmanager build sequence | ||
``` | ||
Usage | ||
--- | ||
```javascript | ||
(function (exports) { | ||
'use strict'; | ||
var Sequence = exports.Sequence || require('sequence').Sequence | ||
, sequence = Sequence.create() | ||
, err | ||
; | ||
sequence | ||
.then(function (next) { | ||
setTimeout(function () { | ||
next(err, "Hi", "World!"); | ||
}, 120); | ||
}) | ||
.then(function (next, err, a, b) { | ||
setTimeout(function () { | ||
next(err, "Hello", b); | ||
}, 270); | ||
}) | ||
.then(function (next, err, a, b) { | ||
setTimeout(function () { | ||
console.log(a, b); | ||
next(); | ||
}, 50); | ||
}); | ||
// so that this example works in browser and node.js | ||
}('undefined' !== typeof exports && exports || new Function('return this')())); | ||
``` |
@@ -1,66 +0,59 @@ | ||
(function () { | ||
/*jshint -W054 */ | ||
;(function (exports) { | ||
"use strict"; | ||
function isSequence(obj) { | ||
return obj instanceof Sequence; | ||
} | ||
function Sequence(defaultContext) { | ||
var me = this | ||
; | ||
function Sequence(global_context) { | ||
var self = this, | ||
waiting = true, | ||
data, | ||
stack = []; | ||
if (!isSequence(this)) { | ||
return new Sequence(global_context); | ||
if (!(this instanceof Sequence)) { | ||
return new Sequence(defaultContext); | ||
} | ||
global_context = global_context || null; | ||
me._waiting = true; | ||
me._data = null; | ||
me._stack = []; | ||
me._defaultContext = defaultContext || null; | ||
function next() { | ||
me._nextBound = function () { | ||
var args = Array.prototype.slice.call(arguments), | ||
seq = stack.shift(); // BUG this will eventually leak | ||
seq = me._stack.shift(); // BUG this will eventually leak | ||
data = arguments; | ||
me._data = arguments; | ||
if (!seq) { | ||
// the chain has ended (for now) | ||
waiting = true; | ||
me._waiting = true; | ||
return; | ||
} | ||
args.unshift(next); | ||
seq.callback.apply(seq.context, args); | ||
} | ||
args.unshift(me._nextBound); | ||
seq.callback.apply(seq._context, args); | ||
}; | ||
} | ||
Sequence.create = Sequence; | ||
function then(callback, context) { | ||
if ('function' !== typeof callback) { | ||
throw new Error("`Sequence().then(callback [context])` requires that `callback` be a function and that `context` be `null`, an object, or a function"); | ||
} | ||
stack.push({ | ||
callback: callback, | ||
context: (null === context ? null : context || global_context), | ||
index: stack.length | ||
}); | ||
Sequence.prototype.then = function (callback, context) { | ||
var me = this | ||
; | ||
// if the chain has stopped, start it back up | ||
if (waiting) { | ||
waiting = false; | ||
next.apply(null, data); | ||
} | ||
if ('function' !== typeof callback) { | ||
throw new Error("`Sequence().then(callback [context])` requires that `callback` be a function and that `context` be `null`, an object, or a function"); | ||
} | ||
me._stack.push({ | ||
callback: callback, | ||
_context: (null === context ? null : context || me._defaultContext), | ||
index: me._stack.length | ||
}); | ||
return self; | ||
// if the chain has stopped, start it back up | ||
if (me._waiting) { | ||
me._waiting = false; | ||
me._nextBound.apply(null, me._data); | ||
} | ||
self.next = next; | ||
self.then = then; | ||
} | ||
return me; | ||
}; | ||
function createSequence(context) { | ||
// TODO use prototype instead of new | ||
return (new Sequence(context)); | ||
} | ||
Sequence.create = createSequence; | ||
Sequence.isSequence = isSequence; | ||
module.exports = Sequence; | ||
}()); | ||
exports.Sequence = Sequence; | ||
}('undefined' !== typeof exports && exports || new Function('return this')())); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
15341
6
0
91
79
1