github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/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  }