mirror of
https://github.com/samuelncui/yatm.git
synced 2026-01-05 13:05:42 +00:00
fix: change tape error
This commit is contained in:
42
tools/context.go
Normal file
42
tools/context.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
type noTimeout struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (c noTimeout) Deadline() (time.Time, bool) { return time.Time{}, false }
|
||||
func (c noTimeout) Done() <-chan struct{} { return nil }
|
||||
func (c noTimeout) Err() error { return nil }
|
||||
func (c noTimeout) Value(key interface{}) interface{} { return c.ctx.Value(key) }
|
||||
|
||||
// WithoutCancel returns a context that is never canceled.
|
||||
func WithoutTimeout(ctx context.Context) context.Context {
|
||||
return noTimeout{ctx: ctx}
|
||||
}
|
||||
|
||||
var (
|
||||
ShutdownContext context.Context
|
||||
)
|
||||
|
||||
func init() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
bgctx, cancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
oscall := <-c
|
||||
log.Printf("system call: %+v", oscall)
|
||||
cancel()
|
||||
}()
|
||||
|
||||
ShutdownContext = bgctx
|
||||
}
|
||||
12
tools/error.go
Normal file
12
tools/error.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/go-multierror"
|
||||
)
|
||||
|
||||
func AppendError(err, e error) error {
|
||||
if err != nil {
|
||||
return multierror.Append(err, e)
|
||||
}
|
||||
return e
|
||||
}
|
||||
19
tools/working.go
Normal file
19
tools/working.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package tools
|
||||
|
||||
import "sync"
|
||||
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
|
||||
func Working() {
|
||||
wg.Add(1)
|
||||
}
|
||||
|
||||
func Done() {
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
func Wait() {
|
||||
wg.Wait()
|
||||
}
|
||||
Reference in New Issue
Block a user