Skip to content

Commit

Permalink
Use try_join!
Browse files Browse the repository at this point in the history
Without using join! or try_join! it will execute the requests
synchronously, rather than firing both of them off at the same time and
waiting for the responses.
  • Loading branch information
thoiberg committed Jul 4, 2023
1 parent 6be5aa0 commit c595c94
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions backend/src/api/satori/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ use std::env;

use axum::Json;
use reqwest::{Client, StatusCode};
use tokio::try_join;

use crate::api::{internal_error, ErrorResponse};

use super::data::{SatoriCurrentCardsResponse, SatoriData, SatoriNewCardsResponse};

pub async fn satori_handler() -> Result<Json<SatoriData>, (StatusCode, Json<ErrorResponse>)> {
let current_cards = get_current_cards().await.map_err(internal_error)?;
let new_cards = get_new_cards().await.map_err(internal_error)?;
let current_cards = get_current_cards();
let new_cards = get_new_cards();

let (current_cards, new_cards) = try_join!(current_cards, new_cards).map_err(internal_error)?;

let satori_data = SatoriData::new(current_cards, new_cards);

Expand Down

0 comments on commit c595c94

Please sign in to comment.