Skip to content

Commit

Permalink
Add "context" to examples
Browse files Browse the repository at this point in the history
A context is now required for the execute method to enable
cancellation.

Thanks to @josegonzalez for bringing this to my attention

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Oct 2, 2023
1 parent 15c40fa commit 5f0a7b6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import (
"fmt"

execute "github.com/alexellis/go-execute/v2"
"context"
)

func main() {
Expand All @@ -69,7 +70,7 @@ func main() {
StreamStdio: false,
}

res, err := cmd.Execute()
res, err := cmd.Execute(context.Background())
if err != nil {
panic(err)
}
Expand All @@ -82,7 +83,6 @@ func main() {
}
```


## Example with "shell" and exit-code 0

```golang
Expand All @@ -92,6 +92,7 @@ import (
"fmt"

execute "github.com/alexellis/go-execute/v2"
"context"
)

func main() {
Expand All @@ -100,7 +101,7 @@ func main() {
Args: []string{"-l"},
Shell: true,
}
res, err := ls.Execute()
res, err := ls.Execute(context.Background())
if err != nil {
panic(err)
}
Expand All @@ -117,6 +118,7 @@ package main
import (
"fmt"

"context"
execute "github.com/alexellis/go-execute/v2"
)

Expand All @@ -125,7 +127,7 @@ func main() {
Command: "exit 1",
Shell: true,
}
res, err := ls.Execute()
res, err := ls.Execute(context.Background())
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 5f0a7b6

Please sign in to comment.