kong icon indicating copy to clipboard operation
kong copied to clipboard

add native context support to Run methods

Open carnott-snap opened this issue 4 years ago • 6 comments

Currently you can manually bind a context.Context to a kong.Context, see #48, but this is not as turnkey as I would have hoped. Would it be possible to add an automatic bind, assuming one is not passed to override, for context.Context that is cancelled when kong.Context.Run returns?

In the override case, I can see arguments for and against, but it may be useful to subcontext via context.WithCancel and explicitly cancel. Need to think through the implications on this one more.

Happy to contribute such a fix, but I thought I would ask if this was wanted first.

carnott-snap avatar Feb 16 '21 21:02 carnott-snap

Ah that is not a bad idea. I can't recall if Kong will allow that default binding to be overridden?

alecthomas avatar Feb 16 '21 22:02 alecthomas

I forgot to say, I would definitely appreciate a PR for this, thanks :)

alecthomas avatar Feb 18 '21 12:02 alecthomas

@carnott-snap I'd be happy to see this contribution too: I've arrived here via #48 and it's not exactly a very elegant workaround – a native context.Context support would be great 🙏

falzm avatar Jul 04 '21 12:07 falzm

Further to this, what would the expected behaviour be if the user subsequently bound a context.Context explicitly?

alecthomas avatar Sep 28 '21 12:09 alecthomas

A context.Context can be used to pass... well, context-bound values (e.g. metadata) down to the execution function. Although some people strongly disagree with this usage of contexts, it's still supported in the standard library and it'd be nice to leverage this technique in Kong.

falzm avatar Sep 28 '21 13:09 falzm

I am aware of what it is... I meant if Kong automatically injects a context.Context, what should occur if the user wants to pass one in? Should Kong not inject its own, error.

alecthomas avatar Sep 28 '21 13:09 alecthomas