Assume you have a compiled jsonata Expression. When calling evaluate() on this Expression concurrently, then $$ appears to resolve to the same underlying object for all evaluate() calls. As a result, one gets unexpected results.
Example - full repro here:
const expression = `
{
"id": $$.id,
"delayed": $slow($$.id)
}
`;
const compiled = jsonata(expression);
...
[
{ id: "aaaaaaaa" },
{ id: "bbbbbbbb" },
{ id: "cccccccc" },
].map((input) => compiled.evaluate(input))
only outputs id cccccccc. The slow async function is part of the expression to amplify the problem.
As an upstream fix, my LLM suggested to create a separate frame per invocation instead of reusing the shared environment. I validated that this fixes the problem, however I am not deep enough in the jsonata source to understand whether this is a sensible fix.
Assume you have a compiled jsonata
Expression. When callingevaluate()on thisExpressionconcurrently, then$$appears to resolve to the same underlying object for allevaluate()calls. As a result, one gets unexpected results.Example - full repro here:
only outputs id
cccccccc. The slow async function is part of the expression to amplify the problem.As an upstream fix, my LLM suggested to create a separate frame per invocation instead of reusing the shared environment. I validated that this fixes the problem, however I am not deep enough in the jsonata source to understand whether this is a sensible fix.