Prevent sequence from starting if already started. Add an id to the sequence, for logging (though the doubling up should discontinue).

This commit is contained in:
mmcw-dev 2017-12-20 23:29:08 -05:00
parent 8333f451f8
commit e1a54c10e0
1 changed files with 9 additions and 2 deletions

View File

@ -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()