目前,我有一个python脚本,它向微服务发出http请求。请求平均需要3秒。
这是我总结的python脚本。
def main():
response = request_to_MS(url)
# This process does not need the response of the microservice.
some_process()
# This is where i actually need a response from the microservice
do_something_with_response(response)
main()
我希望我的脚本能够继续执行代码,并等待类似于typescript的请求响应。
/**
* I'd like to write this kind of code in python.
*/
function get_data(): Promise<string>{
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('This is resolved');
})
})
}
async function main(){
const data = get_data();
console.log('Data variable stores my promise ', data);
// Some process
[1, 2, 3, 4, 5, 6 ,7 ,8].forEach((x: number) => console.log(x));
// I need the promise value here
console.log('En el await', (await data).length)
}
void main();
基本上,我寻找的是完成流程执行所需的时间和微服务的响应时间重叠,从而总体上允许更好的响应时间。
https://stackoverflow.com/questions/56386950
复制相似问题