removeResource<T extends Resource> method
Removes and returns the resource of type T.
If the resource mixes ServiceMixin, its dispose() is fired
(fire-and-forget) so subscriptions / timers it owns don't leak.
Implementation
Option<T> removeResource<T extends Resource>() {
final removed = registry.removeDependencyExact(
TypeEntity(T),
groupEntity: _resourceGroup,
);
final value = switch (removed) {
Some(value: final dep) => switch (dep.value) {
Sync(value: Ok(value: final T v)) => v,
_ => null,
},
None() => null,
};
if (value == null) return const None();
if (value is ServiceMixin) {
(value as ServiceMixin).dispose().end();
}
return Some(value);
}