An example of how to use IPFS Client with threads, using the Abort() and Reset() methods.
An example of how to use IPFS Client with threads, using the Abort() and Reset() methods.
#include <ipfs/client.h>
#include <iostream>
#include <sstream>
#include <thread>
void startThread() {
try {
std::thread thread([&client]() {
std::stringstream contents;
try {
client.
FilesGet(
"QmZp1rrtGTictR2rpNcx4673R7qU9Jdr9DQ6Z7F6Wgo2bQ",
&contents);
std::cout << "Output: " << contents.str() << std::endl;
} catch (const std::runtime_error& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
});
if (thread.joinable()) {
std::cout << "Directly try to abort the request and stop the thread."
<< std::endl;
thread.join();
}
} catch (const std::exception& e) {
std::cerr << "General error: " << e.what() << std::endl;
}
}
int main() {
std::cout << "Starting thread.." << std::endl;
startThread();
std::cout << "Done!" << std::endl;
return 0;
}
IPFS client.
Definition client.h:48
void Reset()
Resets the abort call, allowing to execute new API requests again.
Definition client.cc:483
void FilesGet(const std::string &path, std::iostream *response)
Get a file from IPFS.
Definition client.cc:206
void Abort()
Abort any current running IPFS API request.
Definition client.cc:476