transformAsync method
transform, yielding to the event loop every batch elements so the
UI stays live.
Checks the slice is still valid before each batch: an arena reset while this was waiting throws StateError here rather than letting it carry on writing into memory that now belongs to the next job.
Implementation
Future<void> transformAsync(
T Function(T value) f, {
_I batch = 1 << 16,
}) async {
if (batch <= 0) throw RangeError.value(batch, 'batch');
for (var c = 0; c < _chunks.length; c++) {
var i = 0;
while (true) {
_check();
final List<T> v = _views[c];
if (i >= v.length) break;
final _I end = i + batch < v.length ? i + batch : v.length;
for (; i < end; i++) {
v[i] = f(v[i]);
}
await Future<void>.delayed(.zero);
}
}
}