Check the following code;
isolated class Foo {
private final Bar[] bars = [];
isolated function add(Bar bar) {
lock {
self.bars.push(bar);
}
}
isolated function read() {
foreach Bar bar in self.bars {
var s = start readExternal(bar);
}
}
}
isolated function readExternal(Bar bar) {
}
isolated class Bar {
}
I understand that the self.bars cannot be accessed without a lock statement. But we cannot invoke async calls inside a lock statement either. If we make the Bar class readonly, then we can use cloneReadOnly to get a clone of the bar array and then iterate through. But is there a way to achieve this without making the Bar class readonly (and without cloning the objects)?