import ballerina/io;
public function main() {
// function's default worker, worker `A` and `B` run concurrently.
worker A {
// It is safe to access the parameters of `sayHello` for the
// duration of the function call.
string a = sayHello("John");
io:println(a);
}
worker B {
string b = sayHello("Anne");
io:println(b);
}
// `sayHello` is inferred to be an `isolated` function.
boolean c = sayHello is isolated function (string str) returns string;
io:println(c);
}
function sayHello(string name) returns string {
return "Hello " + name;
}
Inferring isolated
Compiler can inform developer where missing locks are preventing a |
import ballerina/io;
public function main() {
worker A {
function’s default worker, worker A
and B
run concurrently.
string a = sayHello("John");
It is safe to access the parameters of sayHello
for the
duration of the function call.
io:println(a);
}
worker B {
string b = sayHello("Anne");
io:println(b);
}
boolean c = sayHello is isolated function (string str) returns string;
sayHello
is inferred to be an isolated
function.
io:println(c);
}
function sayHello(string name) returns string {
return "Hello " + name;
}
bal run inferring_isolated.bal
true
Hello Anne
Hello John