aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/attribute/attribute_executor.cpp
blob: 4d854bfdca1e1f9bbfa0e5427c33df9f4b03d345 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "attribute_executor.h"
#include "i_attribute_manager.h"
#include <vespa/searchlib/attribute/attributevector.h>
#include <vespa/vespalib/util/isequencedtaskexecutor.h>
#include <future>

using search::AttributeVector;

namespace proton {

AttributeExecutor::AttributeExecutor(std::shared_ptr<IAttributeManager> mgr,
                                     std::shared_ptr<AttributeVector> attr)
    : _mgr(std::move(mgr)),
      _attr(std::move(attr))
{
}

AttributeExecutor::~AttributeExecutor() = default;

void
AttributeExecutor::run_sync(std::function<void()> task) const
{
    vespalib::string name = _attr->getNamePrefix();
    auto& writer = _mgr->getAttributeFieldWriter();
    std::promise<void> promise;
    auto future = promise.get_future();
    auto id = writer.getExecutorIdFromName(name);
    writer.execute(id, [&task, promise=std::move(promise)]() mutable { task(); promise.set_value(); });
    future.wait();
}

} // namespace proton