我对Nodejs非常陌生,来自Java背景。我为长期问题表示歉意。我正在开发独立的Nodejs应用程序,它必须按顺序执行步骤。下面是步骤:NodeJs在连续步骤中调用模块
Step1: The application has to call the external-server-A or else retry
Step2: Once the above call is success, it has to call external-server-b by taking the response on Step1 or else retry.
Step3: Once the above call is success, it has to invoke local module by taking the response-of-step2 and call a function.
不要所有步骤结合起来,1个JS网页,我还想写在不同的JS-页面与上述步骤的功能,并将其导入通过需要()。我不知道如何按顺序调用它们。 我应该在step1函数和step2函数的回调代码块中有require(./step2)
,require(./step3)
。
在此先感谢您的帮助。
Andrew Lively:谢谢你的信息。我会读更多关于承诺。用承诺重试什么是最好的方法。 – John
@John我会建议检查这个问题重试承诺:https://stackoverflow.com/questions/38213668/promise-retry-design-patterns –
如果我必须从app.js文件中调用这些步骤和Step1的响应已传递给Step2然后我该如何做到这一点。 – John