libstore: asyncify Store::connect
Change-Id: I6668295e228092754304ef63cda0b889bd82b198
This commit is contained in:
@@ -244,7 +244,7 @@ static int main_build_remote(AsyncIoRoot & aio, std::string programName, Strings
|
||||
Activity act(*logger, lvlTalkative, actUnknown, fmt("connecting to '%s'", bestMachine->storeUri));
|
||||
|
||||
sshStore = aio.blockOn(bestMachine->openStore());
|
||||
sshStore->connect();
|
||||
aio.blockOn(sshStore->connect());
|
||||
storeUri = bestMachine->storeUri;
|
||||
|
||||
} catch (std::exception & e) {
|
||||
|
||||
@@ -431,9 +431,12 @@ public:
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
void connect() override
|
||||
{
|
||||
kj::Promise<Result<void>> connect() override
|
||||
try {
|
||||
auto conn(connections->get());
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
unsigned int getProtocol() override
|
||||
|
||||
@@ -935,9 +935,12 @@ std::optional<std::string> RemoteStore::getVersion()
|
||||
}
|
||||
|
||||
|
||||
void RemoteStore::connect()
|
||||
{
|
||||
kj::Promise<Result<void>> RemoteStore::connect()
|
||||
try {
|
||||
auto conn(getConnection());
|
||||
co_return result::success();
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
|
||||
std::optional<std::string> getVersion() override;
|
||||
|
||||
void connect() override;
|
||||
kj::Promise<Result<void>> connect() override;
|
||||
|
||||
unsigned int getProtocol() override;
|
||||
|
||||
|
||||
@@ -862,7 +862,7 @@ public:
|
||||
* Establish a connection to the store, for store types that have
|
||||
* a notion of connection. Otherwise this is a no-op.
|
||||
*/
|
||||
virtual void connect() { };
|
||||
virtual kj::Promise<Result<void>> connect() { return {result::success()}; }
|
||||
|
||||
/**
|
||||
* Get the protocol version of this store or it's connection.
|
||||
|
||||
@@ -25,7 +25,7 @@ struct CmdPingStore : StoreCommand, MixJSON
|
||||
{
|
||||
if (!json) {
|
||||
notice("Store URL: %s", store->getUri());
|
||||
store->connect();
|
||||
aio().blockOn(store->connect());
|
||||
if (auto version = store->getVersion())
|
||||
notice("Version: %s", *version);
|
||||
if (auto trusted = store->isTrustedClient())
|
||||
@@ -37,7 +37,7 @@ struct CmdPingStore : StoreCommand, MixJSON
|
||||
});
|
||||
|
||||
res["url"] = store->getUri();
|
||||
store->connect();
|
||||
aio().blockOn(store->connect());
|
||||
if (auto version = store->getVersion())
|
||||
res["version"] = *version;
|
||||
if (auto trusted = store->isTrustedClient())
|
||||
|
||||
Reference in New Issue
Block a user