github.com/iDigitalFlame/xmt@v0.5.4/com/limits/signal_compat.go (about) 1 //go:build !go1.14 2 // +build !go1.14 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 // Package limits contains many options for setting Global limits on how the 21 // overall application behaves. Many of these options are configured by build tags. 22 // 23 // Other functions include re-implemented standard library functions. 24 package limits 25 26 import ( 27 "os" 28 "os/signal" 29 ) 30 31 // StopNotify will stop the signal handling loop from running and will cause 32 // all signal handling to stop. 33 // 34 // This function will block until the Goroutine closes. 35 // 36 // This function has no effect if the loop is not started or stopped. 37 // 38 // The supplied chan can be nil but if non-nil will be passed to 'signal.Stop' 39 // for convince. 40 // 41 // If the Go version is 1.13 or less this function is just a wrapper for 42 // 'signal.Stop'. 43 func StopNotify(c chan<- os.Signal) { 44 if c == nil { 45 return 46 } 47 signal.Stop(c) 48 } 49 50 // Notify causes package signal to relay incoming signals to c. 51 // If no signals are provided, all incoming signals will be relayed to c. 52 // Otherwise, just the provided signals will. 53 // 54 // Package signal will not block sending to c: the caller must ensure 55 // that c has sufficient buffer space to keep up with the expected 56 // signal rate. For a channel used for notification of just one signal value, 57 // a buffer of size 1 is sufficient. 58 // 59 // It is allowed to call Notify multiple times with the same channel: 60 // each call expands the set of signals sent to that channel. 61 // The only way to remove signals from the set is to call Stop. 62 // 63 // It is allowed to call Notify multiple times with different channels 64 // and the same signals: each channel receives copies of incoming 65 // signals independently. 66 // 67 // This version will stop the signal handling loop once the 'StopNotify' 68 // function has been called. 69 // 70 // If the Go version is 1.13 or less this function is just a wrapper for 71 // 'signal.Notify'. 72 func Notify(c chan<- os.Signal, s ...os.Signal) { 73 signal.Notify(c, s...) 74 }