mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-01-02 18:56:41 +00:00
231bebca7d
* Initial import of golang bindings * Updated makefile rules * Updated bindings * Makefile update to add in more tests
31 lines
582 B
Go
Executable File
31 lines
582 B
Go
Executable File
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
)
|
|
|
|
// ContextForSignal returns a context object which is cancelled when a signal
|
|
// is received. It returns nil if no signal parameter is provided
|
|
func ContextForSignal(signals ...os.Signal) context.Context {
|
|
if len(signals) == 0 {
|
|
return nil
|
|
}
|
|
|
|
ch := make(chan os.Signal)
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
// Send message on channel when signal received
|
|
signal.Notify(ch, signals...)
|
|
|
|
// When any signal received, call cancel
|
|
go func() {
|
|
<-ch
|
|
cancel()
|
|
}()
|
|
|
|
// Return success
|
|
return ctx
|
|
}
|