如何识别功能是同步还是异步通信?

问题描述 投票:0回答:1

[我正在Angular 8中工作,我正在使用subscription从服务器获取数据。如何识别它是同步还是异步通信。如果假设是异步的,则如何使其同步,反之亦然。

提前感谢:)

angular asynchronous synchronous
1个回答
0
投票

我认为您正在寻找这个:https://javascript.info/async-await

您可以将异步转换为同步。例如:

const getData = async() => {
  try {
    const response = await fetch('https://sample.com/api/v1');
    // process the response data
  } catch (e) {
    console.log(e);
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.