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

时间:2019-05-07 21:36:08

标签: javascript android async-await parse-server parse-cloud

我有一个异步函数,该函数应该返回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;
});

当我将异步函数更改为普通函数时,它将执行一次并返回期望值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);
        });
    });

这是我从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}")

      }

异步功能可能是什么问题?

1 个答案:

答案 0 :(得分:0)

我试图在解析服务器版本2.8.2中实现异步功能,该功能失败了,但是当我更新到最新版本时,我的异步功能现在返回了预期的结果。

要将包括parse-server在内的所有过时模块更新为最新版本,可以使用以下命令。 -g表示全局模块。可以省略,仅更新过时的本地模块

npm i -g npm-check-updates && ncu -u && npm i
相关问题