@@ -5,9 +5,6 @@ var SequenceError = require('../errors/sequence');
55/**
66 * @method sequence
77 * @description
8- * **Alternative Syntax:**
9- * `sequence(source, {dest, limit, track})` ⇒ `Promise`
10- *
118 * Resolves a dynamic sequence of [mixed values]{@tutorial mixed}.
129 *
1310 * The method acquires [mixed values]{@tutorial mixed} from the `source` function, one at a time, and resolves them,
@@ -31,7 +28,10 @@ var SequenceError = require('../errors/sequence');
3128 *
3229 * Passing in anything other than a function will reject with {@link external:TypeError TypeError} = `Parameter 'source' must be a function.`
3330 *
34- * @param {Function|generator } [dest]
31+ * @param {Object } [options]
32+ * Optional Parameters.
33+ *
34+ * @param {Function|generator } [options.dest=null]
3535 * Optional destination function (or generator), to receive resolved data for each index,
3636 * process it and respond as required.
3737 *
@@ -49,7 +49,7 @@ var SequenceError = require('../errors/sequence');
4949 * If the function throws an error or returns a rejected promise, the sequence terminates,
5050 * and the method rejects with {@link errors.SequenceError SequenceError}, which will have property `dest` set.
5151 *
52- * @param {Number } [limit=0]
52+ * @param {Number } [options. limit=0]
5353 * Limits the maximum size of the sequence. If the value is greater than 0, the method will
5454 * successfully resolve once the specified limit has been reached.
5555 *
@@ -58,7 +58,7 @@ var SequenceError = require('../errors/sequence');
5858 * - `source` either returns or resolves with `undefined`
5959 * - either `source` or `dest` functions throw an error or return a rejected promise
6060 *
61- * @param {Boolean } [track=false]
61+ * @param {Boolean } [options. track=false]
6262 * Changes the type of data to be resolved by this method. By default, it is `false`
6363 * (see the return result). When set to be `true`, the method tracks/collects all resolved data
6464 * into an array internally, and resolves with that array once the method has finished successfully.
@@ -79,19 +79,21 @@ var SequenceError = require('../errors/sequence');
7979 *
8080 * When the method fails, it rejects with {@link errors.SequenceError SequenceError}.
8181 */
82- function sequence ( source , dest , limit , track , config ) {
82+ function sequence ( source , options , config ) {
8383
8484 var $p = config . promise , $utils = config . utils ;
8585
8686 if ( typeof source !== 'function' ) {
8787 return $p . reject ( new TypeError ( 'Parameter \'source\' must be a function.' ) ) ;
8888 }
8989
90- limit = ( limit > 0 ) ? parseInt ( limit ) : 0 ;
9190 source = $utils . wrap ( source ) ;
92- dest = $utils . wrap ( dest ) ;
9391
94- var self = this , data , srcTime , destTime , result = [ ] , start = Date . now ( ) ;
92+ options = options || { } ;
93+
94+ var limit = ( options . limit > 0 ) ? parseInt ( options . limit ) : 0 ,
95+ dest = $utils . wrap ( options . dest ) ,
96+ self = this , data , srcTime , destTime , result = [ ] , start = Date . now ( ) ;
9597
9698 return $p ( function ( resolve , reject ) {
9799
@@ -104,7 +106,7 @@ function sequence(source, dest, limit, track, config) {
104106 if ( data === undefined ) {
105107 success ( ) ;
106108 } else {
107- if ( track ) {
109+ if ( options . track ) {
108110 result . push ( data ) ;
109111 }
110112 if ( dest ) {
@@ -164,7 +166,7 @@ function sequence(source, dest, limit, track, config) {
164166
165167 function success ( ) {
166168 var length = Date . now ( ) - start ;
167- if ( track ) {
169+ if ( options . track ) {
168170 $utils . extend ( result , 'duration' , length ) ;
169171 } else {
170172 result = {
@@ -186,10 +188,7 @@ function sequence(source, dest, limit, track, config) {
186188}
187189
188190module . exports = function ( config ) {
189- return function ( source , dest , limit , track ) {
190- if ( dest && typeof dest === 'object' ) {
191- return sequence . call ( this , source , dest . dest , dest . limit , dest . track , config ) ;
192- }
193- return sequence . call ( this , source , dest , limit , track , config ) ;
191+ return function ( source , options ) {
192+ return sequence . call ( this , source , options , config ) ;
194193 } ;
195194} ;
0 commit comments