mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 18:07:51 +08:00
258fee7712
This addresses #388.
21 lines
453 B
Go
21 lines
453 B
Go
package eval
|
|
|
|
import "errors"
|
|
|
|
// Interrupts returns a channel that is closed when an interrupt signal comes.
|
|
func (ec *EvalCtx) Interrupts() <-chan struct{} {
|
|
return ec.intCh
|
|
}
|
|
|
|
var ErrInterrupted = errors.New("interrupted")
|
|
|
|
// CheckInterrupts checks whether there has been an interrupt, and throws
|
|
// ErrInterrupted if that is the case
|
|
func (ec *EvalCtx) CheckInterrupts() {
|
|
select {
|
|
case <-ec.Interrupts():
|
|
throw(ErrInterrupted)
|
|
default:
|
|
}
|
|
}
|