Adds an object to the registry so that it may be shut down when the application stops.
When shutdown occurs, onClose is invoked and passed object. onClose must return a Future
that fires when object has successfully shutdown. Example:
var streamController = new StreamController();
ResourceRegistry.add(streamController, (controller) => controller.close());
If object has already been registered, this method does nothing.
The return value of this is always object. This allows for concise registration and allocation:
var streamController = ResourceRegistry.add(new StreamController(), (c) => c.close));
Source
static T add<T>(T object, Future onClose(T object)) {
if (_registrations.any((r) => identical(r.object, object))) {
return object;
}
_registrations.add(new _ResourceRegistration(object, onClose));
return object;
}