Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
Is using async/await in promise request more efficient?

What is the best way to make requests?

I have an http request method in project.service.ts. I can make the request with the following structure:

getProjectById(projectId: number) {
  return this.http.get<Project>(`${this.url}/search/projects/${projectId}`).toPromise();
}

And call it with the following structure in project.component.ts:

async getProject(projectId: number) {
  this.isLoading = true;
  try {
    this.project = await this.api.projects.getProjectById(projectId);
  } finally {
    this.isLoading = true;
  }
}

But I can also make the request like this:

async getProjectById(projectId: number) {
  return await this.http.get<Project>(`${this.url}/search/projects/${projectId}`).toPromise();
}

Or this:

getProjectById(projectId: number): Observable<Project> {
  return this.http.get<Project>(`${this.url}/search/project/${projectId}`);
}

But I'd have to subscribe to this function.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is rather question of design of code and clean code, than efficiency. I reckon following the guidelines of Angular built-in Http module.

You need to keep the code clean, and follow the RxJS flow, rather than convert it to async code.

So you need to use this:

getProjectById(projectId: number): Observable<Project> {
  return this.http.get<Project>(`${this.url}/search/project/${projectId}`);
}

If you have no reason, don't complicate it.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda