How to block on asynchronous functions in JavaScript

前端 未结 5 1751
臣服心动
臣服心动 2020-12-09 12:20

I need to write a function in JavaScript, which returns a state from calling an asynchronous function. However, the caller only receives the value and no callback function i

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 12:58

    Why not just:

    asyncCall("request", function() {
        // here you can inspect the state
    });
    

    What's the point of the wrapper function?

    Asynchronous functions work this way. If you want to block the execution, then use a synchronous call:

    var state = syncCall("request");
    

提交回复
热议问题