kareman / SwiftShell

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

Added stop func to stop the task early. added async callbacks for Rea… #18

Closed kenthinson closed 8 years ago

kenthinson commented 8 years ago

This look ok?

kareman commented 8 years ago
/** Callback with when ReadableStream has data.*/
extension ReadableStream {
    public func onOutput ( handler: ((String) -> ())? ) {
        if let h = handler{
            filehandle.readabilityHandler = {(NSFileHandle) in
                if let output = self.readSome(){
                    h(output)
                }
            }
        }
    }
}         
I figured if you are trying to get this callback you are after the string that is currently in the buffer? Again I might be overlooking something :/

Yes in most cases this will be true. But I would still like to leave that decision to the SwiftShell users. Maybe they would like to call readSome several times if they don't get enough output on the first try, or to check if the end has been reached. Maybe they need to get everything at once with read. And in rare cases they may want to just be notified that there is some output without actually fetching the output.

kareman commented 8 years ago

but you can rename the method above to onStringOutput or something like that and use that as a shortcut. I suspect most of the time people will be using that function instead of onOutput.

kenthinson commented 8 years ago

That's a good idea. I've got a lot of homework this week , and my mom just had spine surgery so I'm helping her around the house. so I'm not sure when I'll have time to put together another pull request.

Sent from my iPhone

On Apr 27, 2016, at 5:46 AM, Kare Morstol notifications@github.com wrote:

but you can rename the method above to onStringOutput or something like that and use that as a shortcut. I suspect most of the time people will be using that function instead of onOutput.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub

kareman commented 8 years ago

No problem, I just added some indentation, unit tests and documentation and merged your commits into master. Thanks again for the great work 👍 .

kareman commented 8 years ago

And I hope your mother gets better soon.

kenthinson commented 8 years ago

Thanks :)

Sent from my iPhone

On Apr 27, 2016, at 6:04 PM, Kare Morstol notifications@github.com wrote:

And hope your mother gets better soon.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub