【发布时间】:2021-10-06 14:38:18
【问题描述】:
我有一些(大约 10 个左右)对 API 的请求,并且该 API 的限制为每秒 1 个请求。我想使用 RX JS 在每个函数后暂停。我的代码如下所示:
const source = interval(1000);
const getData = async() => {
let info = {
date: new Date(),
id: initialId,
};
if (fetchInitialResponse(initialId) ) { //external function that checks whether entry exists
info['Names'] = await fetchResponse( getUrl(ADDRESSOTHERNAMES), process.env.OTHERNAMESFOUND);
info['Address'] = await fetchResponse( getUrl(ADDRESSADDRESS), process.env.ADDRESSFOUND);
info['Individuals'] = await fetchResponse( getUrl(ADDRESSINDIVIDUALS), process.env.INDIVIDUALSFOUND);
//and so on with about 10 functions
mongoConnect(true, info) //external function that writes the recieved info to mongodb
}
}
const subscribe = source.subscribe( () => getData() );
如何在每个 'await fetchResponse' 函数后暂停?
【问题讨论】:
标签: javascript rxjs