RequestContextSaverScopeGuard allows to replace the current context without switching back to original context, while ensuring that the original context is restored on guard destruction.

Synopsis

Declared in <folly/io/async/Request.h>

class RequestContextSaverScopeGuard;

Description

The constructor saves the current context but does not replace it; instead, RequestContext::setContext() should be called directly. The original context will be restored on guard destruction. This is different from RequestContextScopeGuard which replaces the current context in construction.

This enables taking advantage of the optimization in setContext() which skips invoking the RequestData callbacks if the new context is the the same as the current one. The use case is processing tasks in a loop which are likely to share the same context.

Member Functions

Name

Description

RequestContextSaverScopeGuard [constructor]

Constructors

~RequestContextSaverScopeGuard [destructor]

Restores the saved context.

operator=

Assignment operators

Protected Member Functions

Name

Description

RequestContextSaverScopeGuard [constructor]

Saves the given context to be restored on destruction.

Created with MrDocs