> > Using `context` is the recommended mechanism to pass timeouts and other > information to functions, > so it's probably already the "best" way, at least from the design point of > view. > > I recommend benchmarking it before searching for other solutions: > if it turns out to cause excessive slowdown, there are some tricks you can > use. >
Yeah, I think I'm going to try using context and switching on Done() in execute() or eval() and at least see what the performance degradation is. I have some pretty good benchmarks so will easily be able to see the change. > A quite hackish solution that just came to my mind is this: > in the GoAWK interpreter you will surely have some "interpreter context" > struct, probably full of often-used pointers. > To set a timeout, you could spawn a goroutine that, after a specified > time, sets one or more of these pointers to nil. > The interpreter would then panic due to a nil pointer dereference, and > you'd need to recover() from that panic in the top-most interpreter > function/method. > And of course you also need to save those pointers somewhere, in order to > restore their values at the beginning of the next interpreter call. > Heh, this is a funky idea. I don't love it and probably won't use it for real :-), but it's a neat idea. Thanks for the response. -Ben -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e34d0542-fd50-4d96-af49-2c3bedb5e195%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.