galenwarren commented on pull request #303:
URL: https://github.com/apache/flink-statefun/pull/303#issuecomment-1050078121


   @sjwiesman 
   
   > Let's suppose in a future version we add the pair a=b as a default bit of 
information to the 
context[1](https://github.com/apache/flink-statefun/pull/303#user-content-fn-1-51415ccdcff656cb887c25acf61bd7df).
 In the current implementation, where we are deriving a new context with the 
pair c=d, that new statefun.Context will lose the original pair a=b
   
   I don't think this would be the case in the current implementation. Consider:
   
   ```
   ctx = statefun.DeriveContext(ctx, context.WithValue(ctx, "key", "value"))
   ```
   
   ... but expanded out a bit:
   
   ```
   func Invoke(ctx statefun.Context, message statefun.Message) error {
   
        // assume ctx contanis a=b when Invoke is called
        newInnerCtx := context.WithValue(ctx, "c", "d")         // newInnerCtx 
ctx holds a=b and c=d
        newCtx := DeriveContext(ctx, newInnerCtx)               // newCtx holds 
a=b and c=d
   }
   ```
   
   The key is that the `context.Context` that is passed as the second parameter 
to `DeriveContext` itself "extends" the original `statefun.Context`, `ctx`. So 
it contains all kv pairs from that original context, plus the new one.
   
   I modified the unit test to demonstrate this, by preloading the initial 
`statefun.Context` with a kv pair and verifying that the kv pair is present in 
the derived context.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to