Files
hatchet/pkg/cmdutils/interrupt.go
abelanger5 5937b9fd98 feat(go-sdk): add ability to create workflows from the Go SDK more easily, quickstart improvements (#30)
* feat: add initial docs site

* feat: allow workflows to be defined from go sdk

* fix release action

* chore: remove server dependencies from client

* fix: use correct certificate for server

* chore: add port and bind address to grpc config

* fix: add env for grpc config

* fix: nil pointer when output is null

* chore: support variation in output args

* fix unresolve merge conflict

* fix: quickstart improvements

* temp remove database url

* fix: action id not required for event

* fix: actionid validation for events

* Remove deleted files
2024-01-02 09:02:53 -05:00

41 lines
821 B
Go

// Adapted from: https://github.com/hatchet-dev/hatchet-v1-archived/blob/3c2c13168afa1af68d4baaf5ed02c9d49c5f0323/cmd/cmdutils/interrupt.go
package cmdutils
import (
"context"
"os"
"os/signal"
"syscall"
)
func InterruptChan() <-chan interface{} {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
ret := make(chan interface{}, 1)
go func() {
s := <-c
ret <- s
close(ret)
}()
return ret
}
func NewInterruptContext() (context.Context, context.CancelFunc) {
interruptChan := InterruptChan()
return InterruptContextFromChan(interruptChan)
}
func InterruptContextFromChan(interruptChan <-chan interface{}) (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-interruptChan
cancel()
}()
return ctx, cancel
}