getAsyncSafe<T> method
See getAsync. Makes an async call by creating a temporary scoped container, attempting to make the async initialization and merging the result with the current container if there is success.
⚠️ Warning: allows reentrancy and does not do error handling. If you call this more than once in parallel it will create multiple Futures - i.e. make multiple async calls. You need to guard against this and perform retries on failure. Be aware that this may happen even if you only call this method in a single location in your app. You may need a an async lock.
Implementation
Future<T> getAsyncSafe<T>() async {
final scope = scoped();
final service = await scope.getAsync<T>();
merge(scope);
return service;
}