MCPcopy Create free account
hub / github.com/cameron314/concurrentqueue / async

Function async

benchmarks/dlib/threads/async.h:68–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66 typename ...Args
67 >
68 std::future<typename impl::result_of<Function(Args...)>::type> async(
69 thread_pool& tp,
70 Function&& f,
71 Args&&... args
72 )
73 {
74 auto prom = std::make_shared<std::promise<typename impl::result_of<Function(Args...)>::type>>();
75 std::future<typename impl::result_of<Function(Args...)>::type> ret = prom->get_future();
76 using bind_t = decltype(std::bind(std::forward<Function>(f), std::forward<Args>(args)...));
77 auto fun = std::make_shared<bind_t>(std::bind(std::forward<Function>(f), std::forward<Args>(args)...));
78 tp.add_task_by_value([fun, prom]()
79 {
80 try
81 {
82 impl::call_prom_set_value(*prom, *fun, impl::selector<typename impl::result_of<Function(Args...)>::type>());
83 }
84 catch(...)
85 {
86 prom->set_exception(std::current_exception());
87 }
88 });
89 return ret;
90 }
91
92// ----------------------------------------------------------------------------------------
93

Callers

nothing calls this directly

Calls 3

call_prom_set_valueFunction · 0.85
add_task_by_valueMethod · 0.80
bindClass · 0.50

Tested by

no test coverage detected