Add an API for binding a callable to an action context
This idea is similar to the idea behind DeferredContext. DeferredContext.addCallback takes a callable and binds it to the active action context. This is great because it gives you a way to preserve an action context across the callbacks on a Deferred which may have no stack-based relationship to each other.
There are other function calls which have no stack-based relationship to the active context. For example, reactor.callLater(...). Perhaps there should be a ReactorContext similar to DeferredContext - but that's a big undertaking and I'm not even sure it would produce good results.
However, a simpler helper which can be used to target a specific callable would be great - since it is a fine-grained tool that can be employed just when it makes sense.
For example, right now, I've just written this code:
d = poll(reactor, get_obj, repeat(0.5, 100))
And I'd really like get_obj there to preserve the action context. A way to do this would be:
from eliot.twisted import bind_action_context
with start_action(...):
d = poll(reactor, bind_action_context(get_obj), repeat(0.5, 100))
The result would be that get_obj has the same Eliot action context as it would have had I instead done:
with start_action(...):
get_obj()
Hm. And you can't/don't want to modify get_obj? Oh, no, cause the issue is the callback-y usage, right.