github.com/mem/u-root@v2.0.1-0.20181004165302-9b18b4636a33+incompatible/cmds/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  }