From 1264dcbd15a45cc61b032d5a6a445d112d488e13 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Thu, 1 Apr 2021 13:00:55 -0700 Subject: [PATCH] change the wording to allow language client to decide how to handle callback state --- specification/metrics/new_api.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/specification/metrics/new_api.md b/specification/metrics/new_api.md index aa13b027aaa..686c8e02332 100644 --- a/specification/metrics/new_api.md +++ b/specification/metrics/new_api.md @@ -352,10 +352,10 @@ The API MUST accept the following parameters: generator, enumerator, etc.). * Individual language client SHOULD define whether this callback function needs to be reentrant safe / thread safe or not. -* An optional `state`. - * The `state` parameter can be used to hold any stateful information. - * If `state` is not provided, the `callback` function MUST take no input - argument, otherwise it MUST take the `state` as the only input argument. + +The API SHOULD provide some way to pass `state` to the callback. Individual +language client can decide what is the idomatic approach (e.g. it could be an +additional parameter, or captured by the lambda closure, or something else). Here are some examples that individual language client might consider: @@ -365,9 +365,9 @@ Here are some examples that individual language client might consider: def pf_callback(): # Note: in the real world these would be retrieved from the operating system return ( - (8, ("pid", 0), ("bitness", 64)), - (37741921, ("pid", 4), ("bitness", 64)), - (10465, ("pid", 880), ("bitness", 32)), + (8, ("pid", 0), ("bitness", 64)), + (37741921, ("pid", 4), ("bitness", 64)), + (10465, ("pid", 880), ("bitness", 32)), ) page_faults_observable_counter = meter.create_observable_counter(name="PF", description="process page faults", pf_callback)