skx/monkey

Ability to cancel a running Monkey Script

iDigitalFlame opened this issue · 1 comments

Was trying to find a way to cancel a running Monkey script (in code directly, not command line based) and I don't see any method to do this properly.

Could there be a possibility of using a Context or something to stop execution in progress?
A change to the Eval function like below would solve some of the issue (The function would bail after the current operation completes)

func Eval(x context.Context, node ast.Node, env *object.Environment) object.Object {
        switch node := node.(type) {
                select {
                        case <-x.Done():
                                return &object.Error{Message: x.Err().Error()}
                        default:
               }
        //Statements

Thanks

skx commented

An obvious issue now you've reported it!

I'd probably prefer to avoid changing the public interface, and would instead suggest adding add an SetContext method, with a default of context.Background.