Closed zhangfisher closed 6 years ago
从字面上看addAsyncFunction就是用来添加异步函数的,所以理所当然也认为async函数也应该是使用addAsyncFunction来添加,而作者对异步函数的定义是,最后一个参数是callback的函数,async函数不是异步函数,应该使用addFunction,因此我也就理所当然地入坑了.
上文只需要将server.addAsyncFunction(hello,"hello");改成server.addFunction(hello,"hello");就可以正常工作了.
Nodejs 10
const hprose=require("hprose") async function hello(name) { return "Hello " + name + "!"; } var server = hprose.Server("http://0.0.0.0:7511"); server.addAsyncFunction(hello,"hello"); server.start();
let client = new hprose.HttpClient("http://127.0.0.1:7511",[ "hello" ]) async function test(){ try{ console.log(await client.hello("aaaaa")) }catch(e){ console.log(e) } } test()
不能正常工作,出错TIMEOUT