MCPcopy Create free account
hub / github.com/davisking/dlib / test_async

Function test_async

dlib/test/threads.cpp:22–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20 logger dlog("test.threads");
21
22 void test_async()
23 {
24#if __cplusplus >= 201103
25 print_spinner();
26 auto v1 = dlib::async([]() { dlib::sleep(500); return 1; }).share();
27 auto v2 = dlib::async([v1]() { dlib::sleep(400); return v1.get()+1; }).share();
28 auto v3 = dlib::async([v2](int a) { dlib::sleep(300); return v2.get()+a; },2).share();
29 auto v4 = dlib::async([v3]() { dlib::sleep(200); return v3.get()+1; });
30
31 DLIB_TEST(v4.get() == 5);
32
33 print_spinner();
34 auto except = dlib::async([](){ dlib::sleep(300); throw error("oops"); });
35 bool got_exception = false;
36 try
37 {
38 except.get();
39 }
40 catch (error&e)
41 {
42 got_exception = true;
43 DLIB_TEST(e.what() == string("oops"));
44 }
45 DLIB_TEST(got_exception);
46#endif
47 }
48
49 class threads_tester : public tester
50 {

Callers 1

perform_testMethod · 0.85

Calls 6

print_spinnerFunction · 0.85
asyncFunction · 0.85
errorClass · 0.85
sleepFunction · 0.50
getMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected