[partners_api] use single network thread for all api

This commit is contained in:
Arsentiy Milchakov 2017-08-14 14:16:42 +03:00 committed by Yuri Gorshenin
parent 580e23357c
commit 6bf8b07db5
6 changed files with 17 additions and 20 deletions

View file

@ -311,7 +311,7 @@ string Api::GetSearchUrl(string const & city, string const & name) const
void Api::GetMinPrice(string const & hotelId, string const & currency,
GetMinPriceCallback const & fn)
{
threads::SimpleThread([hotelId, currency, fn]()
GetPlatform().RunOnNetworkThread([hotelId, currency, fn]()
{
string minPrice;
string priceCurrency;
@ -333,12 +333,12 @@ void Api::GetMinPrice(string const & hotelId, string const & currency,
priceCurrency.clear();
}
fn(hotelId, minPrice, priceCurrency);
}).detach();
});
}
void Api::GetHotelInfo(string const & hotelId, string const & lang, GetHotelInfoCallback const & fn)
{
threads::SimpleThread([hotelId, lang, fn]()
GetPlatform().RunOnNetworkThread([hotelId, lang, fn]()
{
HotelInfo info;
info.m_hotelId = hotelId;
@ -361,7 +361,7 @@ void Api::GetHotelInfo(string const & hotelId, string const & lang, GetHotelInfo
}
fn(info);
}).detach();
});
}
void SetBookingUrlForTesting(string const & url)

View file

@ -114,11 +114,6 @@ http::Result RawApi::GetRentNearby(m2::RectD const & rect,
Api::Api(std::string const & baseUrl /* = kBaseUrl */) : m_baseUrl(baseUrl) {}
Api::~Api()
{
m_worker.Shutdown(base::WorkerThread::Exit::SkipPending);
}
uint64_t Api::GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const & onSuccess,
ErrorCallback const & onError)
{
@ -129,7 +124,7 @@ uint64_t Api::GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const
auto const mercatorRect = MercatorBounds::MetresToXY(latlon.lat, latlon.lon, kSearchRadius);
auto const rect = MercatorBounds::ToLatLonRect(mercatorRect);
m_worker.Push([reqId, rect, onSuccess, onError, baseUrl]() {
GetPlatform().RunOnNetworkThread([reqId, rect, onSuccess, onError, baseUrl]() {
std::vector<RentPlace> result;
auto const rawResult = RawApi::GetRentNearby(rect, baseUrl);

View file

@ -57,7 +57,6 @@ public:
using ErrorCallback = std::function<void(int httpCode, uint64_t const requestId)>;
explicit Api(std::string const & baseUrl = kBaseUrl);
virtual ~Api();
uint64_t GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const & onSuccess,
ErrorCallback const & onError);
@ -68,6 +67,5 @@ public:
private:
uint64_t m_requestId = 0;
std::string m_baseUrl;
base::WorkerThread m_worker;
};
} // namespace cian

View file

@ -1,6 +1,8 @@
#include "partners_api/uber_api.hpp"
#include "partners_api/utils.hpp"
#include "platform/platform.hpp"
#include "geometry/latlon.hpp"
#include "base/logging.hpp"
@ -250,7 +252,7 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
maker->Reset(reqId);
threads::SimpleThread([maker, from, reqId, baseUrl, successFn, errorFn]()
GetPlatform().RunOnNetworkThread([maker, from, reqId, baseUrl, successFn, errorFn]()
{
string result;
if (!RawApi::GetEstimatedTime(from, result, baseUrl))
@ -258,9 +260,9 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
maker->SetTimes(reqId, result);
maker->MakeProducts(reqId, successFn, errorFn);
}).detach();
});
threads::SimpleThread([maker, from, to, reqId, baseUrl, successFn, errorFn]()
GetPlatform().RunOnNetworkThread([maker, from, to, reqId, baseUrl, successFn, errorFn]()
{
string result;
if (!RawApi::GetEstimatedPrice(from, to, result, baseUrl))
@ -268,7 +270,7 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
maker->SetPrices(reqId, result);
maker->MakeProducts(reqId, successFn, errorFn);
}).detach();
});
}
RideRequestLinks Api::GetRideRequestLinks(string const & productId, ms::LatLon const & from,

View file

@ -1,6 +1,7 @@
#include "partners_api/viator_api.hpp"
#include "platform/http_client.hpp"
#include "platform/platform.hpp"
#include "platform/preferred_languages.hpp"
#include "coding/multilang_utf8_string.hpp"
@ -213,7 +214,7 @@ void Api::GetTop5Products(std::string const & destId, std::string const & curren
std::string curr =
kSupportedCurrencies.find(currency) == kSupportedCurrencies.cend() ? "USD" : currency;
threads::SimpleThread([destId, curr, fn]()
GetPlatform().RunOnNetworkThread([destId, curr, fn]()
{
string result;
if (!RawApi::GetTopProducts(destId, curr, 5, result))
@ -233,7 +234,7 @@ void Api::GetTop5Products(std::string const & destId, std::string const & curren
SortProducts(products);
fn(destId, products);
}).detach();
});
}
bool operator<(Product const & lhs, Product const & rhs)

View file

@ -1,6 +1,7 @@
#include "partners_api/yandex_api.hpp"
#include "platform/http_client.hpp"
#include "platform/platform.hpp"
#include "geometry/latlon.hpp"
@ -84,7 +85,7 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
auto const baseUrl = m_baseUrl;
threads::SimpleThread([from, to, baseUrl, successFn, errorFn]()
GetPlatform().RunOnNetworkThread([from, to, baseUrl, successFn, errorFn]()
{
std::string result;
if (!RawApi::GetTaxiInfo(from, to, result, baseUrl))
@ -109,7 +110,7 @@ void Api::GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
else
successFn(products);
}).detach();
});
}
/// Returns link which allows you to launch the Yandex app.