-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.cpp
More file actions
38 lines (33 loc) · 1.14 KB
/
utils.cpp
File metadata and controls
38 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifdef EMSCRIPTEN
# include "utils.hpp"
# include <termcolor/termcolor.hpp>
# include "constants.hpp"
unsigned long get_request_timeout_ms()
{
double timeout_seconds = WASM_HTTP_TRANSPORT_TIMEOUT_DEFAULT;
auto env_var = std::getenv(WASM_HTTP_TRANSPORT_TIMEOUT_NAME.data());
if (env_var != nullptr)
{
try
{
auto value = std::stod(env_var);
if (value <= 0)
{
throw std::runtime_error("negative or zero");
}
timeout_seconds = value;
}
catch (std::exception& e)
{
// Catch failures from (1) stod and (2) timeout <= 0.
// Print warning and use default value.
std::cout << termcolor::yellow << "Warning: environment variable "
<< WASM_HTTP_TRANSPORT_TIMEOUT_NAME
<< " must be a positive number of seconds, using default value of "
<< WASM_HTTP_TRANSPORT_TIMEOUT_DEFAULT << " seconds instead." << termcolor::reset
<< std::endl;
}
}
return 1000 * timeout_seconds;
}
#endif // EMSCRIPTEN