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:
parent
8333f451f8
commit
e1a54c10e0
|
@ -1,5 +1,6 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const uuid = require('uuid').v4
|
||||||
const log = require('../log')('seq')
|
const log = require('../log')('seq')
|
||||||
|
|
||||||
/** Object sequence features */
|
/** Object sequence features */
|
||||||
|
@ -22,6 +23,10 @@ sequence._loop = {
|
||||||
}
|
}
|
||||||
|
|
||||||
sequence.start = function (options, cb) {
|
sequence.start = function (options, cb) {
|
||||||
|
if (sequence._state.active) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
sequence._state.active = true
|
sequence._state.active = true
|
||||||
sequence._state.count = 0
|
sequence._state.count = 0
|
||||||
|
|
||||||
|
@ -41,6 +46,8 @@ sequence.start = function (options, cb) {
|
||||||
}
|
}
|
||||||
sequence._state.stop = cb
|
sequence._state.stop = cb
|
||||||
sequence.step()
|
sequence.step()
|
||||||
|
sequence._state.id = uuid()
|
||||||
|
return sequence._state.id
|
||||||
}
|
}
|
||||||
|
|
||||||
sequence.setStop = function () {
|
sequence.setStop = function () {
|
||||||
|
@ -76,7 +83,7 @@ sequence.step = function () {
|
||||||
if (sequence._state.count > sequence._state.arr.length - 1) {
|
if (sequence._state.count > sequence._state.arr.length - 1) {
|
||||||
return sequence.stop()
|
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](() => {
|
return sequence._state.arr[sequence._state.count](() => {
|
||||||
sequence._state.count++
|
sequence._state.count++
|
||||||
sequence.step()
|
sequence.step()
|
||||||
|
@ -89,7 +96,7 @@ sequence.step = function () {
|
||||||
if (sequence._loop.max > 0 && sequence._loop.count > sequence._loop.max) {
|
if (sequence._loop.max > 0 && sequence._loop.count > sequence._loop.max) {
|
||||||
return sequence.stop()
|
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](() => {
|
return sequence._loop.arr[sequence._state.count](() => {
|
||||||
sequence._state.count++
|
sequence._state.count++
|
||||||
sequence.step()
|
sequence.step()
|
||||||
|
|
Loading…
Reference in New Issue