github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/cmds/core/elvish/eval/interrupts.go (about)

     1  package eval
     2  
     3  import "errors"
     4  
     5  // Interrupts returns a channel that is closed when an interrupt signal comes.
     6  func (fm *Frame) Interrupts() <-chan struct{} {
     7  	return fm.intCh
     8  }
     9  
    10  var ErrInterrupted = errors.New("interrupted")
    11  
    12  // IsInterrupted reports whether there has been an interrupt.
    13  func (fm *Frame) IsInterrupted() bool {
    14  	select {
    15  	case <-fm.Interrupts():
    16  		return true
    17  	default:
    18  		return false
    19  	}
    20  }