Documentation
¶
Overview ¶
Package wasmcontext provides context propagation utilities for the Reglet SDK. It handles converting between Go contexts and the wire format used for WASM host function calls.
Index ¶
- Constants
- func ContextToWire(ctx stdcontext.Context) entities.ContextWire
- func GetCurrentContext() stdcontext.Context
- func ResetContext()
- func SetCurrentContext(ctx stdcontext.Context)
- func WireToContext(parent stdcontext.Context, wire entities.ContextWire) (stdcontext.Context, stdcontext.CancelFunc)
Constants ¶
const RequestIDKey contextKey = "request_id"
RequestIDKey is the context key for request ID.
Variables ¶
This section is empty.
Functions ¶
func ContextToWire ¶
func ContextToWire(ctx stdcontext.Context) entities.ContextWire
ContextToWire converts a stdcontext.Context to ContextWireFormat for sending to the host via host functions.
It extracts: - Deadline (timeout) - Cancellation status - Request ID (key: RequestIDKey)
func GetCurrentContext ¶
func GetCurrentContext() stdcontext.Context
GetCurrentContext returns the current execution context.
This is used by SDK functions (exec, net, log) to get the context for host function calls. If no context has been set, it returns context.Background().
func ResetContext ¶
func ResetContext()
ResetContext resets the global context to background.
This helper function simplifies the cleanup pattern in the plugin lifecyle. It should be called (usually via defer) after an operation completes.
func SetCurrentContext ¶
func SetCurrentContext(ctx stdcontext.Context)
SetCurrentContext sets the current execution context.
This is called by the plugin infrastructure when the host invokes an exported function (describe, schema, observe). It updates the global context used for the duration of the execution.
func WireToContext ¶
func WireToContext(parent stdcontext.Context, wire entities.ContextWire) (stdcontext.Context, stdcontext.CancelFunc)
WireToContext converts a ContextWireFormat to a stdcontext.Context. This is used when the host provides context information to the plugin.
If parent is nil, context.Background() is used. Returns the new context and its CancelFunc.
Types ¶
This section is empty.