Extracting return value from nested callback function

前端 未结 2 770
清酒与你
清酒与你 2021-01-28 19:47

To simplify my question i did some modifications to the code. I am now able to get the value from the callback function i now want to pass this data into a variable.

2条回答
  •  灰色年华
    2021-01-28 20:44

    You're calling handleServerResponse when you send the request, not in the callback. It should be:

    var doesErrorsExist = postToServer(function() {
        handleServerResponse(containers, function (args) {
            return args;
        });
    });
    

    But this still won't work -- an asynchronous function can never return a value to its caller, because the value won't exist until the operation completes after the function returns.

    I haven't tried to figure out the logic of everything you're trying to do, so I don't have a concrete suggestion for how to fix that. I think if you reread the question you linked to, you should get some more insight.

提交回复
热议问题