1 /*
2  * WaitUtils.hpp
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 
16 #ifndef CORE_WAITUTILS_HPP
17 #define CORE_WAITUTILS_HPP
18 
19 #include <boost/function.hpp>
20 
21 #include <shared_core/Error.hpp>
22 
23 namespace rstudio {
24 namespace core {
25 
26 
27 enum WaitResultType {
28    WaitSuccess,
29    WaitContinue,
30    WaitError
31 };
32 
33 struct WaitResult
34 {
WaitResultrstudio::core::WaitResult35    WaitResult(WaitResultType type, Error error)
36       : type(type), error(error)
37    {
38    }
39 
40    WaitResultType type;
41    Error error;
42 };
43 
44 Error waitWithTimeout(const boost::function<WaitResult()>& connectFunction,
45                       int initialWaitMs = 30,
46                       int incrementWaitMs = 10,
47                       int maxWaitSec = 10);
48 
49 } // namespace core
50 } // namespace rstudio
51 
52 #endif // CORE_WAITUTILS_HPP
53