Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
59 lines (50 loc) · 1.15 KB

File metadata and controls

59 lines (50 loc) · 1.15 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
*
* @file task_timeout.cpp
* @author Gaspard Kirira
*
* Copyright 2025, Gaspard Kirira.
* All rights reserved.
* https://github.com/vixcpp/vix
*
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*
*/
#include <chrono>
#include <iostream>
#include <thread>
#include <vix/threadpool/all.hpp>
int main()
{
vix::threadpool::ThreadPool pool(2);
vix::threadpool::TaskOptions options;
options.set_timeout(vix::threadpool::Timeout::milliseconds(50));
auto future =
pool.submit(
[]()
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
return 42;
},
options);
try
{
const int value = future.get();
std::cout << "Result: " << value << '\n';
}
catch (const std::exception &e)
{
std::cout << "Task failed: " << e.what() << '\n';
}
std::cout << "Future status: "
<< vix::threadpool::to_string(future.status())
<< '\n';
std::cout << "Future result: "
<< vix::threadpool::to_string(future.result())
<< '\n';
pool.shutdown();
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.