diff --git a/lib/sequence/index.js b/lib/sequence/index.js index 6c2a8ff..b1af7a6 100644 --- a/lib/sequence/index.js +++ b/lib/sequence/index.js @@ -39,17 +39,20 @@ sequence.start = function (options, cb) { } else { sequence._loop.max = 0 } - + sequence._state.stop = cb sequence.step() } -sequence.stop = function (next) { +sequence.setStop = function () { + sequence._state.active = false +} + +sequence.stop = function () { sequence._state.active = false sequence._state.count = 0 sequence._loop.count = 0 - console.dir(sequence._state.stop) - console.trace() - if (next) next() + if (sequence._state.stop) sequence._state.stop() + sequence._state.stop = null } sequence.pause = function () { @@ -63,12 +66,15 @@ sequence.resume = function () { sequence.step = function () { if (sequence._state.active && !sequence._state.paused) { - if (sequence._state.arr.length > 0 && typeof sequence._state.arr[sequence._state.count] !== 'undefined') { + if (sequence._state.arr.length > 0) { + if (sequence._state.count > sequence._state.arr.length) { + return sequence.stop() + } return sequence._state.arr[sequence._state.count](() => { sequence._state.count++ sequence.step() }) - } else if (sequence._loop.arr.length > 0 && typeof sequence._loop.arr[sequence._state.count] !== 'undefined') { + } else if (sequence._loop.arr.length > 0) { if (sequence._state.count > sequence._loop.arr.length) { sequence._state.count = 0 sequence._loop.count++