1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #ifndef BASE_TASK_RUNNER_UTIL_H_
- #define BASE_TASK_RUNNER_UTIL_H_
- #include <memory>
- #include <utility>
- #include "base/bind.h"
- #include "base/callback.h"
- #include "base/logging.h"
- #include "base/post_task_and_reply_with_result_internal.h"
- #include "base/task_runner.h"
- namespace base {
- template <typename TaskReturnType, typename ReplyArgType>
- bool PostTaskAndReplyWithResult(TaskRunner* task_runner,
- const Location& from_here,
- OnceCallback<TaskReturnType()> task,
- OnceCallback<void(ReplyArgType)> reply) {
- DCHECK(task);
- DCHECK(reply);
-
- auto* result = new std::unique_ptr<TaskReturnType>();
- return task_runner->PostTaskAndReply(
- from_here,
- BindOnce(&internal::ReturnAsParamAdapter<TaskReturnType>, std::move(task),
- result),
- BindOnce(&internal::ReplyAdapter<TaskReturnType, ReplyArgType>,
- std::move(reply), Owned(result)));
- }
- }
- #endif
|