makeDeferredAttenuatorsProvider = (
  compartments,
  compartmentDescriptors,
) => {
  /** @type {DeferredAttenuatorsProvider['import']} */
  let importAttenuator;
  let defaultAttenuator;
  // Attenuators compartment is not created when there's no policy.
  // Errors should be thrown when the provider is used.
  if (!compartmentDescriptors[ATTENUATORS_COMPARTMENT]) {
    importAttenuator = async () => {
      throw Error(`No attenuators specified in policy`);
    };
  } else {
    defaultAttenuator =
      compartmentDescriptors[ATTENUATORS_COMPARTMENT].policy.defaultAttenuator;

    // At the time of this function being called, attenuators compartment won't
    // exist yet, we need to defer looking them up in the compartment to the
    // time of the import function being called.
    /**
     *
     * @param {string | null} attenuatorSpecifier
     * @returns {Promise<Attenuator>}
     */
    importAttenuator = async attenuatorSpecifier => {
      if (!attenuatorSpecifier) {
        if (!defaultAttenuator) {
          throw Error(`No default attenuator specified in policy`);
        }
        attenuatorSpecifier = defaultAttenuator;
      }
      const { namespace } = await compartments[ATTENUATORS_COMPARTMENT].import(
        /** @type {string} */ (attenuatorSpecifier),
      );
      return namespace;
    };
  }

  return { import: importAttenuator };
}
Makes an async provider for attenuators
@param {Record<string, Compartment>} compartments
@param {Record<string, CompartmentDescriptor>} compartmentDescriptors
@returns {DeferredAttenuatorsProvider}