pull/149/head
FongMi 2 years ago
parent acee4f6b0d
commit 7ceeb13eeb
  1. 1
      quickjs/src/main/java/com/fongmi/quickjs/crawler/Spider.java
  2. 4
      quickjs/src/main/java/com/fongmi/quickjs/method/Async.java
  3. 15
      quickjs/src/main/java/com/fongmi/quickjs/method/Function.java

@ -61,6 +61,7 @@ public class Spider extends com.github.catvod.crawler.Spider {
}
private Object call(String func, Object... args) throws Exception {
//return executor.submit((Function.call(jsObject, func, args))).get();
return CompletableFuture.supplyAsync(() -> Async.run(jsObject, func, args), executor).join().get();
}

@ -35,11 +35,11 @@ public class Async {
private CompletableFuture<Object> then(Object result) {
JSObject promise = (JSObject) result;
JSFunction then = promise.getJSFunction("then");
if (then != null) then.call(func);
if (then != null) then.call(callback);
return future;
}
private final JSCallFunction func = new JSCallFunction() {
private final JSCallFunction callback = new JSCallFunction() {
@Override
public Object call(Object... args) {
future.complete(args[0]);

@ -25,15 +25,20 @@ public class Function implements Callable<Object> {
@Override
public Object call() throws Exception {
result = object.getJSFunction(name).call(args);
if (!(result instanceof JSObject)) return result;
JSFunction function = object.getJSFunction(name);
if (function == null) return null;
result = function.call(args);
if (result instanceof JSObject) then(result);
return result;
}
private void then(Object result) {
JSObject promise = (JSObject) result;
JSFunction then = promise.getJSFunction("then");
if (then != null) then.call(func);
return result;
if (then != null) then.call(callback);
}
private final JSCallFunction func = new JSCallFunction() {
private final JSCallFunction callback = new JSCallFunction() {
@Override
public Object call(Object... args) {
return result = args[0];

Loading…
Cancel
Save