SNIP_ADAPTIVE_STD_FIGURE_Figure_6_19
Wortlaut
Figure 6.19: Returning Future with already set result As you see in the example above: Inside the body of the service method an internal method is called, which does the work synchronously . I.e. after the return of ‘doAdjustInternal’ inout the attributes, which resemble the service methods out-params are set. Then this out value is set at the Promise and then the Future created from the Promise is returned. This has the effect that the caller, who gets this Future as return, can immediately call Future::get(), which would not block, but immediately return the AdjustOutput. Now let’s have a look at the asynchronous worker thread variant: 1 using namespace ara::com; 2 3 // our implementation of RadarService 4 class RadarServiceImpl : public RadarServiceSkeleton { 5 6 public: 7 Future<AdjustOutput> Adjust(const Position& position) 8 { 9 Promise<AdjustOutput> promise; 10 auto future = promise.get_future(); 11 12 // asynchronous call to internal adjust function in a new Thread 13 std::thread t( 14 [this] (const Position& pos, Promise prom) { prom.set_value( doAdjustInternal(pos));}, 15 std::cref(position), std::move(promise)); 16 17 //we return a future, which might be set or not at this point... 18 return future; 19 } 20 21 private: 22 AdjustOutput doAdjustInternal(const Position& position) { 23 // ... implementation 24 } 25 }
Versionen & Provenienz · Zugeordnete Anforderungen
Diese Angaben zeigt der Versions-Explorer.
Begründung & Zuweisungs-Evidenz
Setting value on Promise via set_value.
Dokumenten-Herkunft & Rückverfolgbarkeit
| Spezifikations-Dokument | ARAComAPI.pdf |
|---|---|
| Dokumentseite | Seite 1 |
| Ziel-Modul | com (adaptive) |
| Ziel-Anforderung | SWS_CORE_00345 |
| Semantische Rolle | heuristic |
| Automatisierungs-Konfidenz | 0.85 |