package eval

import (
	
	
	
	
)

// Interrupts returns a channel that is closed when an interrupt signal comes.
func ( *Frame) () <-chan struct{} {
	return .intCh
}

// ErrInterrupted is thrown when the execution is interrupted by a signal.
var ErrInterrupted = errors.New("interrupted")

// IsInterrupted reports whether there has been an interrupt.
func ( *Frame) () bool {
	select {
	case <-.Interrupts():
		return true
	default:
		return false
	}
}

// ListenInterrupts returns a channel that is closed when SIGINT or SIGQUIT
// has been received by the process. It also returns a function that should be
// called when the channel is no longer needed.
func () (<-chan struct{}, func()) {
	 := make(chan os.Signal)
	signal.Notify(, syscall.SIGINT, syscall.SIGQUIT)
	// Channel to return, closed after receiving the first SIGINT or SIGQUIT.
	 := make(chan struct{})

	// Closed in the cleanup function to request the relaying goroutine to stop.
	 := make(chan struct{})
	// Closed in the relaying goroutine to signal that it has stopped.
	 := make(chan struct{})

	go func() {
		 := false
	:
		for {
			select {
			case <-:
				if ! {
					close()
					 = true
				}
			case <-:
				break 
			}
		}
		signal.Stop()
		close()
	}()

	return , func() {
		close()
		<-
	}
}