C++

std::async & std::future

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

std::async nis një punë në sfond dhe të kthen menjëherë një std::future — një „biletë“ për rezultatin. Kur të duhet rezultati, thërret .get(), dhe ai pret nëse puna s'ka mbaruar ende.

EnglishEN

std::async starts a job in the background and immediately gives you a std::future — a “ticket” for the result. When you need the result, you call .get(), which waits if the job isn't finished yet.

Si ta mendosh

Si bileta e rrobaqepësit: ia lë pantallonat, merr biletën, dhe kur kthehesh i merr të gatshme.

Lexoje në anglisht

Like a tailor's ticket: you drop off the trousers, take the ticket, and collect them ready when you come back.

Shembull kodicpp

#include <future>
auto rezultati = std::async([] { return llogaritGjate(); });
// ... punë tjetër
std::cout << rezultati.get();

Terma të lidhur