Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.2k views
in Technique[技术] by (71.8m points)

JS:怎么让多个进程回调得到的不同值,在方法中同时使用?

比如说有一个function A,里面用了exec这种开启进程的方法,exec会返回数据a。
然后有一个function B,里面也用了exec这种开启进程的方法,exec会返回数据b。

现在的问题是:
有一个function C,需要同时使用a、b的值,所以等function A和B执行完后,才能执行C。

那么,怎么做到A、B都执行完了再执行C?

提前谢谢大佬们!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

把function A和B分别包装成一个Promise,然后在C中使用Promise.all


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...