| 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 | { |
no test coverage detected