addResource method
Register resource
to call impl
when invoked.
If this server is already initialized and still connected to a client, then the client will be notified that the resources list has changed.
Throws a StateError if there is already a Resource registered with the same name.
Implementation
void addResource(
Resource resource,
FutureOr<ReadResourceResult> Function(ReadResourceRequest) impl,
) {
if (_resources.containsKey(resource.uri)) {
throw StateError(
'Failed to add resource ${resource.name}, there is already a '
'resource that exists at the URI ${resource.uri}.',
);
}
_resources[resource.uri] = resource;
_resourceImpls[resource.uri] = impl;
if (ready) {
_notifyResourceListChanged();
}
}