@@ -2104,37 +2104,36 @@ SubscriptionKey Request::subscribe(SubscriptionParams&& params, SubscriptionCall
21042104 return key;
21052105}
21062106
2107- SubscriptionKey Request::subscribe (std::launch launch, SubscriptionParams&& params, SubscriptionCallback&& callback)
2107+ std::future< SubscriptionKey> Request::subscribe (std::launch launch, SubscriptionParams&& params, SubscriptionCallback&& callback)
21082108{
2109- const auto key = subscribe (std::move (params), std::move (callback));
2110- const auto itrOperation = _operations.find (std::string { strSubscription });
2111- const auto itrSubscription = _subscriptions.find (key);
2112-
2113- if (itrOperation != _operations.cend ()
2114- && itrSubscription != _subscriptions.cend ())
2109+ return std::async (launch, [spThis = shared_from_this (), launch](SubscriptionParams&& paramsFuture, SubscriptionCallback&& callbackFuture)
21152110 {
2116- const auto & operation = itrOperation->second ;
2117- const auto & registration = itrSubscription->second ;
2118- response::Value emptyFragmentDirectives (response::Type::Map);
2119- const SelectionSetParams selectionSetParams {
2120- ResolverContext::NotifySubscribe,
2121- registration->data ->state ,
2122- registration->data ->directives ,
2123- emptyFragmentDirectives,
2124- emptyFragmentDirectives,
2125- emptyFragmentDirectives,
2126- {},
2127- launch,
2128- };
2111+ const auto key = spThis->subscribe (std::move (paramsFuture), std::move (callbackFuture));
2112+ const auto itrOperation = spThis->_operations .find (std::string { strSubscription });
2113+ const auto itrSubscription = spThis->_subscriptions .find (key);
21292114
2130- std::async (launch,
2131- [](std::future<response::Value> document )
2115+ if (itrOperation != spThis-> _operations . cend ()
2116+ && itrSubscription != spThis-> _subscriptions . cend () )
21322117 {
2133- return document.get ();
2134- }, operation->resolve (selectionSetParams, registration->selection , registration->data ->fragments , registration->data ->variables )).get ();
2135- }
2118+ const auto & operation = itrOperation->second ;
2119+ const auto & registration = itrSubscription->second ;
2120+ response::Value emptyFragmentDirectives (response::Type::Map);
2121+ const SelectionSetParams selectionSetParams {
2122+ ResolverContext::NotifySubscribe,
2123+ registration->data ->state ,
2124+ registration->data ->directives ,
2125+ emptyFragmentDirectives,
2126+ emptyFragmentDirectives,
2127+ emptyFragmentDirectives,
2128+ {},
2129+ launch,
2130+ };
2131+
2132+ operation->resolve (selectionSetParams, registration->selection , registration->data ->fragments , registration->data ->variables ).get ();
2133+ }
21362134
2137- return key;
2135+ return key;
2136+ }, std::move (params), std::move (callback));
21382137}
21392138
21402139void Request::unsubscribe (SubscriptionKey key)
@@ -2166,36 +2165,35 @@ void Request::unsubscribe(SubscriptionKey key)
21662165 }
21672166}
21682167
2169- void Request::unsubscribe (std::launch launch, SubscriptionKey key)
2168+ std::future< void > Request::unsubscribe (std::launch launch, SubscriptionKey key)
21702169{
2171- const auto itrOperation = _operations.find (std::string { strSubscription });
2172- const auto itrSubscription = _subscriptions.find (key);
2173-
2174- if (itrOperation != _operations.cend ()
2175- && itrSubscription != _subscriptions.cend ())
2170+ return std::async (launch, [spThis = shared_from_this (), launch, key]()
21762171 {
2177- const auto & operation = itrOperation->second ;
2178- const auto & registration = itrSubscription->second ;
2179- response::Value emptyFragmentDirectives (response::Type::Map);
2180- const SelectionSetParams selectionSetParams {
2181- ResolverContext::NotifyUnsubscribe,
2182- registration->data ->state ,
2183- registration->data ->directives ,
2184- emptyFragmentDirectives,
2185- emptyFragmentDirectives,
2186- emptyFragmentDirectives,
2187- {},
2188- launch,
2189- };
2172+ const auto itrOperation = spThis->_operations .find (std::string { strSubscription });
2173+ const auto itrSubscription = spThis->_subscriptions .find (key);
21902174
2191- std::async (launch,
2192- [](std::future<response::Value> document )
2175+ if (itrOperation != spThis-> _operations . cend ()
2176+ && itrSubscription != spThis-> _subscriptions . cend () )
21932177 {
2194- return document.get ();
2195- }, operation->resolve (selectionSetParams, registration->selection , registration->data ->fragments , registration->data ->variables )).get ();
2196- }
2178+ const auto & operation = itrOperation->second ;
2179+ const auto & registration = itrSubscription->second ;
2180+ response::Value emptyFragmentDirectives (response::Type::Map);
2181+ const SelectionSetParams selectionSetParams {
2182+ ResolverContext::NotifyUnsubscribe,
2183+ registration->data ->state ,
2184+ registration->data ->directives ,
2185+ emptyFragmentDirectives,
2186+ emptyFragmentDirectives,
2187+ emptyFragmentDirectives,
2188+ {},
2189+ launch,
2190+ };
2191+
2192+ operation->resolve (selectionSetParams, registration->selection , registration->data ->fragments , registration->data ->variables ).get ();
2193+ }
21972194
2198- unsubscribe (key);
2195+ spThis->unsubscribe (key);
2196+ });
21992197}
22002198
22012199void Request::deliver (const SubscriptionName& name, const std::shared_ptr<Object>& subscriptionObject) const
0 commit comments