Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Handle protocol to get asynchronous output #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gwikiera
Copy link

@gwikiera gwikiera commented Jan 26, 2018

I've created a protocol Handle to handle command output asynchronously. All previously FileHandle arguments of shellOut methods have been replaced by Handle. FileHandle implements Handle so it's completely backward compatible. StringHandle converts Data output into String one.

It fixes #11.

@iainsmith
Copy link

This looks good. @JohnSundell would you like any changes before merging this?

We could then add the implementation from @SteveBarnegren in #22 so that users can use FileHandle.standardOuput & FileHandle.standardError. I've tested out #22 locally.

private extension FileHandle {
     var shouldBeClosed: Bool {
         return self !== FileHandle.standardOutput &&
             self !== FileHandle.standardError &&
             self !== FileHandle.standardInput
     }
 }

extension FileHandle: Handle {
    public func handle(data: Data) {
        write(data)
    }
    
    public func endHandling() {
        if shouldBeClosed { closeFile() }
       // alternative using naming from #22
       // if !isStandard { closeFile() }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async output?
2 participants