text: kernel.api.regulator = def(
    [
      kernel.fp.array,
      kernel.fp.functions
    ],
  
    function (ar, fn) {
      var create = function (sources) {
        /*
         * 1. Resolve configuration as much as possible
         * 2. Check for unresolved modulator types that are required to continue.
         *   a) Go ahead and resolve, if we have everything we need.
         *   b) Delay, requiring the modulators, then retry.
         */
        var regulate = function (ids, define, require, demand, onsuccess, onerror) {
          sources.crank();
          var required = ar.map(ids, determinetype);
          var unresolved = ar.filter(required, fn.not(sources.isResolved));
          if (unresolved.length === 0)
            resolve(ids,  define, require, demand, onsuccess, onerror);
          else
            delay(unresolved, ids, define, require, demand, onsuccess, onerror);
        };
  
        var resolve = function (ids,  define, require, demand, onsuccess, onerror) {
          var r = [];
          for (var i = 0; i < ids.length; ++i) {
            var id = ids[i];
            var source = sources.find(id);
            if (source.notfound) {
              onerror('Could not find source for module [' +  id + ']');
              return;
            }
            var spec = source.found.get(id, define, require, demand);
            r[i] = build(id, spec);
          }
          onsuccess(r);
        };
  
        var build = function (id, spec) {
          return {
            id: id,
            url: spec.url,
            load: spec.load,
            serial: spec.serial
          };
        };
  
        var delay = function (types, ids, define, require, demand, onsuccess, onerror) {
          var modulatorids = ar.map(types, sources.idOf);
          require(modulatorids, function (/* modulators */) {
            var modulators = arguments;
            ar.each(types, function (type, i) {
               sources.register(type, modulators[i]);
            });
            regulate(ids, define, require, demand, onsuccess, onerror);
          });
        };
  
        var determinetype = function (id) {
          var index = id.indexOf('!');
          return index === -1 ? 'bolt' : id.substring(0, index);
        };
  
        return {
          regulate: regulate
        };
      };
  
      return {
        create: create
      };
    }
  );
  