简体   繁体   English

如何继续等待一个功能完成?

[英]How to wait for one function to finish before continuing?

I have three functions. 我有三个功能。 The calling hierarchy is like this: 调用层次结构是这样的:

function a() {
    b();
    c();
}

function b() {
    d();
}

What I want is to finish b then continue doing c. 我想要完成b然后继续执行c。 But d is asynchronous. 但是d是异步的。 I don't have rights to change anything in b and d. 我无权更改b和d中的任何内容。 Is there any way to handle this case? 有什么办法可以处理这种情况? Sorry for my English. 对不起我的英语不好。

Almost certainly not. 几乎可以肯定。 You need a callback, a promise, or an event. 您需要一个回调,一个promise或一个事件。

Since you can't change b() , you can't add a callback argument to d() (assuming it accepted one in the first place) and you can't capture the return value of d() (assuming it returned a promise in the first place). 由于您无法更改b() ,因此无法向d()添加回调参数(假设它首先接受了一个参数),并且无法捕获d()的返回值(假设它返回a首先保证)。

We have no way of telling if d() triggers an event on the DOM when it is done (or even if you are running the JS in a context where there is a DOM). 我们无法确定d()是否在完成时(或即使您在存在DOM的上下文中运行JS)在DOM上触发事件。

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

相关问题 等待一项功能完成后再继续? - Wait for one function to finish before continuing? 在继续之前等待一个功能完成的正确方法? - Proper way to wait for one function to finish before continuing? 在继续之前等待一个 function 完成的最佳方法是什么? - what the best way to wait for one function to finish before continuing? 如何在继续之前等待递归 function 完全完成? - How can I wait for a recursive function to completely finish before continuing? 等待函数完成,然后再继续使用JavaScript - Wait for a function to finish before continuing in javascript 等待函数完成,然后再继续执行$ .each函数中的下一个循环 - wait for the function to finish before continuing to the next loop in a $.each function javascript-等到功能完成再继续 - javascript- Wait till function finish before continuing 获取功能以等待后期中间件保存完成后再继续 - Getting a function to wait for a post middleware save to finish before continuing 我如何让我的 javascript 函数在继续之前等待 WebSql 事务完成 - How i make my javascript function wait to WebSql transactions to finish before continuing 如何在继续下一行代码之前等待 .map() 完成执行 - How to wait for .map() to finish executing before continuing on to next lines of code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM