import ballerina/io;
type Update record {
int updateIndex;
int stockMnt;
};
public function main() returns error? {
Update newUpdate = {
updateIndex: 132,
stockMnt: 3500
};
transaction {
check exec(newUpdate);
check commit;
}
}
// A `transactional` function can only be called from a `transactional` context
transactional function exec(Update u) returns error? {
// A `transactional` named worker starts a transaction branch
// in the current transaction.
transactional worker A {
bar();
}
}
transactional function bar() {
io:println("bar() invoked");
}
Transactional named workersA named worker within a transactional function can be declared as |
import ballerina/io;
type Update record {
int updateIndex;
int stockMnt;
};
public function main() returns error? {
Update newUpdate = {
updateIndex: 132,
stockMnt: 3500
};
transaction {
check exec(newUpdate);
check commit;
}
}
transactional function exec(Update u) returns error? {
A transactional
function can only be called from a transactional
context
transactional worker A {
bar();
}
}
A transactional
named worker starts a transaction branch
in the current transaction.
transactional function bar() {
io:println("bar() invoked");
}
bal run transactional_named_workers.bal
bar() invoked