kareman / SwiftShell

A Swift framework for shell scripting.
https://kareman.github.io/SwiftShell
MIT License
1.03k stars 87 forks source link

TIming out a command #62

Closed sohocoke closed 6 years ago

sohocoke commented 6 years ago

I’m looking for a way to abort execution of a command based on a timeout, and ideally, a more generic condition that is periodically checked.

Since it appears this is not currently possible, I’d like to ask what interface change to add this feature would be best.

Off the cuff, I can think of changing #run(…) to have a closure argument () -> Bool that defaults to { return false }. I could then implement a timeout using some suitable timer primitive, ideally available across platforms (so probably not NSTimer / GCD?).

Before I roll up my sleeves I’d love to hear how this sounds.

kareman commented 6 years ago

Hi, and thank you for the suggestion, but this functionality is not specific to running shell commands so I don't think it's a good fit for this project. SwiftShell already supports terminating a running command:

let eternalCommand = runAsync("...")

// ...

eternalCommand.stop()

So you can call eternalCommand.stop() from any delayed or repeating code block.

kareman commented 6 years ago

Sorry, forgot that functionality has not been released yet. But it is available in the latest beta 4.1.0-beta.2.

sohocoke commented 6 years ago

Ah nice, that sounds like exactly what I need. Thanks!