github.com/blend/go-sdk@v1.20220411.3/graceful/notify.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package graceful
     9  
    10  import (
    11  	"os"
    12  	"os/signal"
    13  )
    14  
    15  // Notify returns a channel that listens for a given set of os signals.
    16  func Notify(signals ...os.Signal) chan os.Signal {
    17  	return NotifyWithCapacity(1, signals...)
    18  }
    19  
    20  // NotifyWithCapacity returns a channel with a given capacity
    21  // that listens for a given set of os signals.
    22  func NotifyWithCapacity(capacity int, signals ...os.Signal) chan os.Signal {
    23  	terminateSignal := make(chan os.Signal, capacity)
    24  	signal.Notify(terminateSignal, signals...)
    25  	return terminateSignal
    26  }