reactiverse / es4x

🚀 fast JavaScript 4 Eclipse Vert.x
https://reactiverse.io/es4x/
Apache License 2.0
881 stars 75 forks source link

invokeMember (then) on io.vertx.core.impl.future.PromiseImpl@47ddaaf5 failed due to: Arity error - expected: 2 actual: 1 #586

Closed fantasy0v0 closed 2 years ago

fantasy0v0 commented 2 years ago
$ es4x versions
VM:        OpenJDK 64-Bit Server VM - 17
VM Vendor: null
Vert.x:    4.2.2
ES4X:      0.16.2
graaljs:   21.3.0

code: index.js

import { Promise as VPromise } from "@vertx/core";
let promise = VPromise.promise();
promise.future().then(v => {
  console.log("v:" + v);
  return "v2";
});
setTimeout(() => {
  promise.complete("v1");
}, 1000);

error message:

Failed in deploying verticle caused by TypeError: invokeMember (then) on io.vertx.core.impl.future.PromiseImpl@47ddaaf5 failed due to: Arity error - expected: 2 actual: 1
        at <js> :anonymous(/C:/Users/fan/Desktop/test/demo/index.js:9-12:204-274)
        at <js> _load(node_modules\.lib\es4x-0.16.2.jar!\io\reactiverse\es4x\jvm-npm.js:73:2195-2276)
        at <js> runMain(node_modules\.lib\es4x-0.16.2.jar!\io\reactiverse\es4x\jvm-npm.js:85:2567-2611)
        at org.graalvm.sdk/org.graalvm.polyglot.Value.invokeMember(Value.java:934)
        at io.reactiverse.es4x.impl.JSVerticleFactory$1.lambda$start$0(JSVerticleFactory.java:85)
        at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:159)
        at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
        at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:157)
        at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:833)

I found that 'then' must have two parameters.

The following code executes normally.

let promise = VPromise.promise();
promise.future().then(v => {
  console.log("v:" + v);
  return "v2";
}, err => {

});
setTimeout(() => {
  promise.complete("v1");
}, 1000);
pmlopes commented 2 years ago

@fantasy0v0 you shouldn't use vert.x promise, the method you're seeing is a instrumented version to comply to graalvm.

You should use the built in promise from JavaScript.