Skip to content

Commit 5f0a7b6

Browse files
committed
Add "context" to examples
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) <[email protected]>
1 parent 15c40fa commit 5f0a7b6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import (
6060
"fmt"
6161

6262
execute "github.com/alexellis/go-execute/v2"
63+
"context"
6364
)
6465

6566
func main() {
@@ -69,7 +70,7 @@ func main() {
6970
StreamStdio: false,
7071
}
7172

72-
res, err := cmd.Execute()
73+
res, err := cmd.Execute(context.Background())
7374
if err != nil {
7475
panic(err)
7576
}
@@ -82,7 +83,6 @@ func main() {
8283
}
8384
```
8485

85-
8686
## Example with "shell" and exit-code 0
8787

8888
```golang
@@ -92,6 +92,7 @@ import (
9292
"fmt"
9393

9494
execute "github.com/alexellis/go-execute/v2"
95+
"context"
9596
)
9697

9798
func main() {
@@ -100,7 +101,7 @@ func main() {
100101
Args: []string{"-l"},
101102
Shell: true,
102103
}
103-
res, err := ls.Execute()
104+
res, err := ls.Execute(context.Background())
104105
if err != nil {
105106
panic(err)
106107
}
@@ -117,6 +118,7 @@ package main
117118
import (
118119
"fmt"
119120

121+
"context"
120122
execute "github.com/alexellis/go-execute/v2"
121123
)
122124

@@ -125,7 +127,7 @@ func main() {
125127
Command: "exit 1",
126128
Shell: true,
127129
}
128-
res, err := ls.Execute()
130+
res, err := ls.Execute(context.Background())
129131
if err != nil {
130132
panic(err)
131133
}

0 commit comments

Comments
 (0)