diff --git a/lib/sequence/index.js b/lib/sequence/index.js index d785ad9..f60d86e 100644 --- a/lib/sequence/index.js +++ b/lib/sequence/index.js @@ -1,5 +1,6 @@ 'use strict' +const uuid = require('uuid').v4 const log = require('../log')('seq') /** Object sequence features */ @@ -22,6 +23,10 @@ sequence._loop = { } sequence.start = function (options, cb) { + if (sequence._state.active) { + return false + } + sequence._state.active = true sequence._state.count = 0 @@ -41,6 +46,8 @@ sequence.start = function (options, cb) { } sequence._state.stop = cb sequence.step() + sequence._state.id = uuid() + return sequence._state.id } sequence.setStop = function () { @@ -76,7 +83,7 @@ sequence.step = function () { if (sequence._state.count > sequence._state.arr.length - 1) { return sequence.stop() } - log.info('step', sequence._state.count) + log.info('step', { count : sequence._state.count, id : sequence._state.id }) return sequence._state.arr[sequence._state.count](() => { sequence._state.count++ sequence.step() @@ -89,7 +96,7 @@ sequence.step = function () { if (sequence._loop.max > 0 && sequence._loop.count > sequence._loop.max) { return sequence.stop() } - log.info('step', sequence._state.count) + log.info('step', { count : sequence._state.count, id : sequence._state.id }) return sequence._loop.arr[sequence._state.count](() => { sequence._state.count++ sequence.step()