mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-12-10 17:18:20 -05:00
Factor run_in_background out from preserve_fn
It annoys me that we create temporary function objects when there's really no need for it. Let's factor the gubbins out of preserve_fn and start using it.
This commit is contained in:
parent
8ffaacbee3
commit
20f40348d4
2 changed files with 32 additions and 27 deletions
|
|
@ -279,9 +279,9 @@ Obviously that option means that the operations done in
|
|||
that might be fixed by setting a different logcontext via a ``with
|
||||
LoggingContext(...)`` in ``background_operation``).
|
||||
|
||||
The second option is to use ``logcontext.preserve_fn``, which wraps a function
|
||||
so that it doesn't reset the logcontext even when it returns an incomplete
|
||||
deferred, and adds a callback to the returned deferred to reset the
|
||||
The second option is to use ``logcontext.run_in_background``, which wraps a
|
||||
function so that it doesn't reset the logcontext even when it returns an
|
||||
incomplete deferred, and adds a callback to the returned deferred to reset the
|
||||
logcontext. In other words, it turns a function that follows the Synapse rules
|
||||
about logcontexts and Deferreds into one which behaves more like an external
|
||||
function — the opposite operation to that described in the previous section.
|
||||
|
|
@ -293,7 +293,7 @@ It can be used like this:
|
|||
def do_request_handling():
|
||||
yield foreground_operation()
|
||||
|
||||
logcontext.preserve_fn(background_operation)()
|
||||
logcontext.run_in_background(background_operation)
|
||||
|
||||
# this will now be logged against the request context
|
||||
logger.debug("Request handling complete")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue