chromium/base/threading/post_task_and_reply_impl.h

// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file defines a common helper encapsulating the tricky bits of
// implementing PostTaskAndReply(). These tricky bits are specifically around
// handling of the reply callback and ensuring it is deleted on the correct
// sequence.

#ifndef BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_
#define BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_

#include <utility>

#include "base/base_export.h"
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/memory/scoped_refptr.h"
#include "base/task/sequenced_task_runner.h"

namespace base::internal {

class BASE_EXPORT PostTaskAndReplyRelay {};

// Precondition: `SequencedTaskRunner::HasCurrentDefault()` must be true.
//
// Posts `task` by calling `task_poster`. On completion, posts `reply` to the
// origin sequence. Each callback is deleted synchronously after running, or
// scheduled for asynchronous deletion on the origin sequence if it can't run
// (e.g. if a TaskRunner skips it on shutdown). In this case, the callback may
// leak: see `SequencedTaskRunner::DeleteSoon()` for details about when objects
// scheduled for asynchronous deletion can be leaked.
//
// Note: All //base task posting APIs require callbacks to support deletion on
// the posting sequence if they can't be scheduled.
template <typename TaskPoster>
bool PostTaskAndReplyImpl(TaskPoster task_poster,
                          const Location& from_here,
                          OnceClosure task,
                          OnceClosure reply) {}

}  // namespace base::internal

#endif  // BASE_THREADING_POST_TASK_AND_REPLY_IMPL_H_