Search code examples
concurrencyballerinaballerina-swan-lake

Invalid start action accessing a non isolated expression


See the code segment below. I have two variables that are not primitive. context is a record, and keywords is a string array. It shows me the below error. What should be the fix here? I cannot fully understand what the error message tells me.

enter image description here


Solution

  • To use a start action within an isolated function, the function that is being called has to be an isolated function and all of the arguments have to be isolated expressions. The errors are because context is not final and it is mutable and keywords are also mutable.

    The solution is to provide context.clone() and keywords.clone() as arguments, which will create new values and isolate the expressions.

    Refer: https://ballerina.io/learn/by-example/run-strands-safely-on-separate-threads/