✏️ Context not Cotext
This commit is contained in:
parent
56fd7bf0b4
commit
1abe398c7a
3 changed files with 7 additions and 4 deletions
|
|
@ -7,7 +7,11 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SelfCancelingCotext(ctx context.Context) (context.Context, context.CancelFunc) {
|
func SelfCancelingContextFromBackground() (context.Context, context.CancelFunc) {
|
||||||
|
return SelfCancelingContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func SelfCancelingContext(ctx context.Context) (context.Context, context.CancelFunc) {
|
||||||
c, done := context.WithCancel(ctx)
|
c, done := context.WithCancel(ctx)
|
||||||
ch := make(chan os.Signal, 1)
|
ch := make(chan os.Signal, 1)
|
||||||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
@ -26,7 +25,7 @@ func main() {
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, done := c.SelfCancelingCotext(context.Background())
|
ctx, done := c.SelfCancelingContextFromBackground()
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
var walker convids.ShowWalker
|
var walker convids.ShowWalker
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, done := c.SelfCancelingCotext(context.Background())
|
ctx, done := c.SelfCancelingContext(context.Background())
|
||||||
defer done()
|
defer done()
|
||||||
ctx = chill.Chill(ctx)
|
ctx = chill.Chill(ctx)
|
||||||
s := spin.Spin(ctx, "Waiting for CPU to cool...")
|
s := spin.Spin(ctx, "Waiting for CPU to cool...")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue