简体   繁体   English

解析服务器云异步功能不返回结果

[英]Parse server cloud async function not returning the result

I have an async function which should return true or false but it's been executed several times according to the logs instead of once and end but returning an i/o failure error message instead of the expected value. 我有一个async函数应该返回truefalse但是它已经根据日志而不是一次和结束执行了几次但是返回了一个i/o failure错误消息而不是预期的值。

Parse.Cloud.define("updateMatch", async (request) => {
    const query = new Parse.Query("Match");
    query.equalTo("league", request.params.league);
    const results = await query.find();

    var match = null;
    if (results.length > 0) {
        match = results[0];
    }else{
          var Match = Parse.Object.extend("Match");
            match = new Match();
            match.set("groupId", request.params.Id);
    }
     match.set("stadium",request.params.stadium);
     var saved = await match.save(null, { useMasterKey: true });
    return true;
});

When i changes the async function to a normal function, it get executed once and returns the expected value which is true 当我将异步函数更改为普通函数时,它会执行一次并返回期望值,该值为true

 Parse.Cloud.define("updateMatch", function(request,response){
        const query = new Parse.Query("Match");
        query.equalTo("league", request.params.league);
        query.find().then((results)=>{
         var match = null;
        if (results.length > 0) {
            match = results[0];
        }else{
              var Match = Parse.Object.extend("Match");
                match = new Match();
                match.set("groupId", request.params.Id);
        }
         match.set("stadium",request.params.stadium);
         match.save(null, { useMasterKey: true });
        return response.success(true);
        });
    });

This is the way I'm calling the function from android 这是我从android调用函数的方式

val params = HashMap<String, Any>()
    params["league"] = "EPA"
    params["groupId"] = "A"
    params["stadium"] = "Etihad"

    ParseCloud.callFunctionInBackground("updateMatch", params,FunctionCallback { success, e ->
       AppLogger.error("success? ${success} error is ${e?.message}")

      }

What could be the problem with the async function? 异步函数有什么问题?

I was trying to implement async functions in parse-server version 2.8.2 which failed but when i updated to the latest version, my async functions now return the expected results. 我试图在parse-server版本2.8.2实现async函数失败但是当我更新到最新版本时,我的异步函数现在返回预期的结果。

To update all outdated modules including parse-server to the latest versions, the command below can be used. 要将所有过时的模块(包括parse-server)更新到最新版本,可以使用以下命令。 -g means global modules. -g表示全局模块。 it can be omitted to only update outdated local modules 可以省略它只更新过时的本地模块

npm i -g npm-check-updates && ncu -u && npm i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM