aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/tlssyncer.cpp
blob: 259d02f460459a32937abe44f13b5d236e2a588d (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
35
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "tlssyncer.h"
#include "igetserialnum.h"
#include <vespa/vespalib/util/threadexecutor.h>
#include <vespa/vespalib/util/lambdatask.h>
#include <vespa/searchlib/transactionlog/syncproxy.h>
#include <future>

using vespalib::makeLambdaTask;
using search::SerialNum;

namespace proton {

TlsSyncer::TlsSyncer(vespalib::ThreadExecutor &executor,
                     const IGetSerialNum &getSerialNum,
                     search::transactionlog::SyncProxy &proxy)
    : _executor(executor),
      _getSerialNum(getSerialNum),
      _proxy(proxy)
{
}


void
TlsSyncer::sync()
{
    std::promise<SerialNum> promise;
    std::future<SerialNum> future = promise.get_future();
    _executor.execute(makeLambdaTask([&]() { promise.set_value(_getSerialNum.getSerialNum()); }));
    SerialNum serialNum = future.get();
    _proxy.sync(serialNum);
}

}