use of org.apache.sling.scripting.sightly.js.impl.async.UnaryCallback in project sling by apache.
the class UseFunction method use.
private Object use(List<String> depNames, final Function callback, final Context cx, final Scriptable scope) {
final AsyncContainer asyncContainer = new AsyncContainer();
if (depNames.isEmpty()) {
callImmediate(callback, asyncContainer, cx, scope);
} else {
final int[] counter = { depNames.size() };
final Object[] dependencies = new Object[depNames.size()];
for (int i = 0; i < depNames.size(); i++) {
final int dependencyPos = i;
dependencyResolver.resolve(depNames.get(i), new UnaryCallback() {
@Override
public void invoke(Object arg) {
counter[0]--;
dependencies[dependencyPos] = arg;
if (counter[0] == 0) {
Object result = JsUtils.callFn(callback, cx, scope, thisObj, dependencies);
asyncContainer.complete(result);
}
}
});
}
}
return asyncContainer;
}
Aggregations