Closed scotthovestadt closed 8 years ago
Yeah - this is a bit more tricky so was going to get to it at some point. Probably going to add in a cancel
method to vorpal.command
.
Not sure a cancel method will work for long-running commands. I think we may need a cancel event?
We can fire an event, but I believe we should have a cancel
method that just fires a function for convenience. The only purpose of this is cleanup. For example, something like this:
vorpal
.command('do things repeatedly', function(){
const self = this;
setInterval(function(){
if (self._cancelled) {
// break off
}
}, 1000);
})
.cancel(function() {
this._cancelled = true;
});
What do you think?
Yeah, you're right. It's similar to the way Bluebird did it for Promises: http://bluebirdjs.com/docs/api/cancellation.html
PS: Let's also support calling the cancel() method on a promise if it exists...?
Captain epic (@jackyjieliu) here fixed this with https://github.com/dthree/vorpal/pull/62. I just tested this and fixed a final bug. Looks good.
Currently, my command keeps on running.