Skip to content

Commit 7a1f63a

Browse files
authored
[GraphBolt] Move the function object into gb::async. (#7655)
1 parent 7deeff6 commit 7a1f63a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

graphbolt/include/graphbolt/async.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ class Future : public torch::CustomClassHolder {
102102
* task to avoid spawning a new OpenMP threadpool on each interop thread.
103103
*/
104104
template <typename F>
105-
inline auto async(F function) {
105+
inline auto async(F&& function) {
106106
using T = decltype(function());
107107
#ifdef BUILD_WITH_TASKFLOW
108-
auto future = interop_pool().async(function);
108+
auto future = interop_pool().async(std::move(function));
109109
#else
110110
auto promise = std::make_shared<std::promise<T>>();
111111
auto future = promise->get_future();
112-
at::launch([=]() {
112+
at::launch([promise, func = std::move(function)]() {
113113
if constexpr (std::is_void_v<T>) {
114-
function();
114+
func();
115115
promise->set_value();
116116
} else
117-
promise->set_value(function());
117+
promise->set_value(func());
118118
});
119119
#endif
120120
return c10::make_intrusive<Future<T>>(std::move(future));

0 commit comments

Comments
 (0)