Skip to content

Commit

Permalink
move cmd output out of func.
Browse files Browse the repository at this point in the history
  • Loading branch information
melbahja committed Oct 31, 2021
1 parent 87a38e1 commit 60d40bf
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ func (c *Cmd) init() (err error) {
return nil
}

// Command with context output.
type ctxCmdOutput struct {
output []byte
err error
}

// Executes the given callback within session. Sends SIGINT when the context is canceled.
func (c *Cmd) runWithContext(callback func() ([]byte, error)) ([]byte, error) {
type commandOutput struct {
output []byte
err error
}
outputChan := make(chan commandOutput)
outputChan := make(chan ctxCmdOutput)
go func() {
output, err := callback()
outputChan <- commandOutput{
outputChan <- ctxCmdOutput{
output: output,
err: err,
}
Expand Down

0 comments on commit 60d40bf

Please sign in to comment.