Wait for async task to finish

后端 未结 2 2121
灰色年华
灰色年华 2020-12-13 05:52

I\'m interacting with a third-party JavaScript library where some function calls are asynchronous. Instead of working the asynchronous logic into my application, I preferred

2条回答
  •  抹茶落季
    2020-12-13 06:39

    How about calling a function from within your callback instead of returning a value in sync_call()?

    function sync_call(input) {
        var value;
    
        // Assume the async call always succeed
        async_call(input, function(result) {
            value = result;
            use_value(value);
        } );
    }
    

提交回复
热议问题