libstore: asyncify Store::connect

Change-Id: I6668295e228092754304ef63cda0b889bd82b198
This commit is contained in:
eldritch horrors
2025-03-05 16:42:11 +01:00
parent 87efae8a53
commit a783d2c0d9
6 changed files with 15 additions and 9 deletions
+1 -1
View File
@@ -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) {
+5 -2
View File
@@ -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
+5 -2
View File
@@ -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();
}
+1 -1
View File
@@ -165,7 +165,7 @@ public:
std::optional<std::string> getVersion() override;
void connect() override;
kj::Promise<Result<void>> connect() override;
unsigned int getProtocol() override;
+1 -1
View File
@@ -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.
+2 -2
View File
@@ -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())