Wraps PromiseProxy factory and caches instances in a WeakMap
185577
function CachedPromiseProxy(target, context, cache = new WeakMap(), factory = PromiseProxy) {
  const cached = cache.get(target)
  if (cached) {
    return cached
  }
  const obj = factory(target, context,
    (target, context) => CachedPromiseProxy(target, context, cache))
  cache.set(target, obj)
  return obj
}
525838
function loadSingle ( path, parentUrl, baseUrl, cache ) {
	var promise, url;

	url = resolvePath( path, path[0] === '.' ? parentUrl : baseUrl );

	// if this component has already been requested, don't
	// request it again
	if ( !cache || !promises[ url ] ) {
		promise = get$1( url ).then( function ( template ) {
			return new Promise( function ( fulfil, reject ) {
				make( template, {
					url: url,
					loadImport: function ( name, path, parentUrl, callback ) {
						// if import has a relative URL, it should resolve
						// relative to this (parent). Otherwise, relative
						// to load.baseUrl
						loadSingle( path, parentUrl, baseUrl, cache ).then( callback, reject );
					},
					require: ractiveRequire
				}, fulfil, reject );
			});
		});

		promises[ url ] = promise;
	}

	return promises[ url ];
}
346156
private Templates tryCache(String url) throws Exception {
        Templates x = (Templates) m_cache.get(url);
        if (x == null) {
            synchronized (m_cache) {
                if (!m_cache.containsKey(url)) {
                    TransformerFactory factory = TransformerFactory.newInstance();
                    if (factory.getClass().getName().equals("net.sf.saxon.TransformerFactoryImpl")) {
                        factory.setAttribute(FeatureKeys.VERSION_WARNING, Boolean.FALSE);
                    }
                    StreamSource ss = new StreamSource(getInputStream(url));
                    ss.setSystemId(url);
                    x = factory.newTemplates(ss);
                    m_cache.put(url, x);
                }
            }
        }
        return x;
    }
699207
function mapAfterAllReturn(arr, mapper, returnValue) {
  const results = new Array(arr.length);
  let containsPromise = false;

  for (let i = 0, l = arr.length; i < l; ++i) {
    results[i] = mapper(arr[i]);

    if (isPromise(results[i])) {
      containsPromise = true;
    }
  }

  if (containsPromise) {
    return Promise.all(results).then(() => returnValue);
  } else {
    return returnValue;
  }
}
1087371
private void loadAllInstances(ZooClassProxy def, boolean subClasses, 
			MergingIterator<ZooPC> iter, boolean loadFromCache) {
		for (Node n: nodes) {
			iter.add(n.loadAllInstances(def, loadFromCache));
		}
		
		if (subClasses) {
			for (ZooClassProxy sub: def.getSubProxies()) {
				loadAllInstances(sub, true, iter, loadFromCache);
			}
		}
	}
677084
function prepareFunc(func, builder, basepath) { //Prepare an implied function for repeated use
  funcStringCache[func] = funcStringCache[func] || ('(function() { with (proxy(scope)) { return ('+func.toString()+')('+defaultScopeName+'); } })()');

  return function(scope) {
    var scope = scope || {};
    var builder = builder || stringBuilder;
    var proxy = jshtmlProxy(new builder(basepath));
    var ret = eval(funcStringCache[func]);
    if (ret && typeof(ret.then) === 'function') { //looks like a promise. Let's use it why don't we?
      ret.proxy = proxy;
      return ret;
    }
    return proxy.collect();
  }
}
1345163
function createFixtures(entity) {
        return new Promise(function(resolve, reject) {
            if (!entity.fixtures) return resolve();
            return Promise.all(entity.fixtures.map(function(fixture) {
                CRUD.fromCache(entity.getType(), fixture).Persist(true);
            })).then(resolve, reject);
        });
    }
1337307
function disposeInstance(container, workPromise, renderCompletePromise) {
                var bindings = _ElementUtilities.data(container).bindTokens;
                if (bindings) {
                    bindings.forEach(function (binding) {
                        if (binding && binding.cancel) {
                            binding.cancel();
                        }
                    });
                }
                if (workPromise) {
                    workPromise.cancel();
                }
                if (renderCompletePromise) {
                    renderCompletePromise.cancel();
                }
            }
717757
function streamify(promise, factory) {
  var _then = promise.then;
  promise.then = function() {
    factory();
    var newPromise = _then.apply(promise, arguments);
    return streamify(newPromise, factory);
  };
  promise.stream = factory;
  return promise;
}
880794
function createInternalInjector(cache, factory) {

    function getService(serviceName, caller) {
      if (cache.hasOwnProperty(serviceName)) {
        if (cache[serviceName] === INSTANTIATING) {
          throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
                    serviceName + ' <- ' + path.join(' <- '));
        }
        return cache[serviceName];
      } else {
        try {
          path.unshift(serviceName);
          cache[serviceName] = INSTANTIATING;
          return cache[serviceName] = factory(serviceName, caller);
        } catch (err) {
          if (cache[serviceName] === INSTANTIATING) {
            delete cache[serviceName];
          }
          throw err;
        } finally {
          path.shift();
        }
      }
    }

    function invoke(fn, self, locals, serviceName) {
      if (typeof locals === 'string') {
        serviceName = locals;
        locals = null;
      }

      var args = [],
          $inject = createInjector.$$annotate(fn, strictDi, serviceName),
          length, i,
          key;

      for (i = 0, length = $inject.length; i < length; i++) {
        key = $inject[i];
        if (typeof key !== 'string') {
          throw $injectorMinErr('itkn',
                  'Incorrect injection token! Expected service name as string, got {0}', key);
        }
        args.push(
          locals && locals.hasOwnProperty(key)
          ? locals[key]
          : getService(key, serviceName)
        );
      }
      if (isArray(fn)) {
        fn = fn[length];
      }

      // http://jsperf.com/angularjs-invoke-apply-vs-switch
      // #5388
      return fn.apply(self, args);
    }

    function instantiate(Type, locals, serviceName) {
      // Check if Type is annotated and use just the given function at n-1 as parameter
      // e.g. someModule.factory('greeter', ['$window', function(renamed$window) {}]);
      // Object creation: http://jsperf.com/create-constructor/2
      var instance = Object.create((isArray(Type) ? Type[Type.length - 1] : Type).prototype || null);
      var returnedValue = invoke(Type, instance, locals, serviceName);

      return isObject(returnedValue) || isFunction(returnedValue) ? returnedValue : instance;
    }

    return {
      invoke: invoke,
      instantiate: instantiate,
      get: getService,
      annotate: createInjector.$$annotate,
      has: function(name) {
        return providerCache.hasOwnProperty(name + providerSuffix) || cache.hasOwnProperty(name);
      }
    };
  }
1168759
async function mkProxyOrMockFile({dirPath, exclude, targetDir, proxyFolderName,
    mockFolderName, time, interval, isProxy, libPath}) {
//@formatter:on
    
    const relativePath = dirPath.replace(targetDir, '') || '/';
    const childList = await loadChildList(dirPath, exclude);

    const taskList = childList.map(child => {
        return ((async function handleFile() {
            const stat = await Fs.stat(Path.join(dirPath, child));
            if (stat.isFile()) {
                const fileRelativePath = relativePath + child;
                const isWs = _.endsWith(child, '-ws.js');

                const factory = {
                    'proxy_api'() {
                        return Render(PROXY_TPL,
                            {note: Common.NOTE, proxyFolderName, fileRelativePath});
                    },
                    'mock_api'() {
                        return Render(MOCK_API_TPL,
                            {note: Common.NOTE, mockFolderName, fileRelativePath, time});
                    },
                    'proxy_ws'() {
                        return Render(PROXY_TPL,
                            {note: Common.NOTE, proxyFolderName, fileRelativePath});
                    },
                    'mock_ws'() {
                        return Render(MOCK_WS_TPL, {
                            note: Common.NOTE,
                            mockFolderName,
                            fileRelativePath,
                            interval
                        });
                    }
                }[`${isProxy ? 'proxy' : 'mock'}_${isWs ? 'ws' : 'api'}`]();

                await Fs.writeFile(Path.join(libPath, child), factory);
                return;
            }

            if (stat.isDirectory()) {
                await mkProxyOrMockFile({
                    dirPath: Path.join(dirPath, child), exclude, targetDir, proxyFolderName,
                    mockFolderName, time, interval, isProxy, libPath
                });
            }
        })());
    });

    await Promise.all(taskList);
}
759168
private ProfilingWrapper wrap(Base object) {
    ProfilingWrapper res = new ProfilingWrapper(context, resource, object);
    res.cache = cache;
    res.engine = engine;
    return res;
  }
519705
private static KunderaProxy getProxyInstance(Class factory, CglibLazyInitializer instance)
    {
        KunderaProxy proxy;
        try
        {
            Enhancer.registerCallbacks(factory, new Callback[] { instance, null });
            proxy = (KunderaProxy) factory.newInstance();
        }
        catch (IllegalAccessException e)
        {
            throw new LazyInitializationException(e);
        }
        catch (InstantiationException e)
        {
            throw new LazyInitializationException(e);
        }
        finally
        {
            Enhancer.registerCallbacks(factory, null);
        }
        return proxy;
    }
737849
def provider_factory(factory=_sentinel, scope=NoneScope):
    '''
    
    '''
    if factory is _sentinel:
        return functools.partial(provider_factory, scope=scope)
    provider = Provider(factory, scope)
    return provider
1000895
function (executor) {
    /*  optionally support non-constructor/plain-function call  */
    if (!(this instanceof api))
      return new api(executor);

    /*  initialize object  */
    this.id           = "Thenable/1.0.7";
    this.state        = STATE_PENDING; /*  initial state  */
    this.fulfillValue = undefined;     /*  initial value  */     /*  [Promises/A+ 1.3, 2.1.2.2]  */
    this.rejectReason = undefined;     /*  initial reason */     /*  [Promises/A+ 1.5, 2.1.3.2]  */
    this.onFulfilled  = [];            /*  initial handlers  */
    this.onRejected   = [];            /*  initial handlers  */

    /*  provide optional information-hiding proxy  */
    this.proxy = {
      then: this.then.bind(this)
    };

    /*  support optional executor function  */
    if (typeof executor === "function")
      executor.call(this, this.fulfill.bind(this), this.reject.bind(this));
  }
1017655
function compileRender(templateSource, data, block) {
  const hash = md5(templateSource);

  return Promise.try(() => {
    const cached = compileRenderCache.get(hash);
    if (cached) {
      compileRenderCache.ttl(hash);
      return cached;
    }

    const templateFunction = precompile(templateSource, {})
      .then(code => evaluate(code));

    compileRenderCache.set(hash, templateFunction);
    return templateFunction;
  }).then((templateFunction) => {
    if (block) {
      templateFunction = templateFunction.blocks && templateFunction.blocks[block];
    }
    if (!templateFunction) {
      return '';
    }

    return runtime(Benchpress.helpers, data, templateFunction);
  }).catch((err) => {
    err.message = `Render failed for template ${templateSource.slice(0, 20)}:\n ${err.message}`;
    err.stack = `Render failed for template ${templateSource.slice(0, 20)}:\n ${err.stack}`;

    throw err;
  });
}
406399
@Skip
    @Override
    public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
                     ChannelPromise promise) throws Exception {
        ctx.bind(localAddress, promise);
    }