@@ -2104,6 +2104,39 @@ SubscriptionKey Request::subscribe(SubscriptionParams&& params, SubscriptionCall
21042104 return key;
21052105}
21062106
2107+ SubscriptionKey Request::subscribe (std::launch launch, SubscriptionParams&& params, SubscriptionCallback&& callback)
2108+ {
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 ())
2115+ {
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+ };
2129+
2130+ std::async (launch,
2131+ [](std::future<response::Value> document)
2132+ {
2133+ return document.get ();
2134+ }, operation->resolve (selectionSetParams, registration->selection , registration->data ->fragments , registration->data ->variables )).get ();
2135+ }
2136+
2137+ return key;
2138+ }
2139+
21072140void Request::unsubscribe (SubscriptionKey key)
21082141{
21092142 auto itrSubscription = _subscriptions.find (key);
@@ -2133,6 +2166,38 @@ void Request::unsubscribe(SubscriptionKey key)
21332166 }
21342167}
21352168
2169+ void Request::unsubscribe (std::launch launch, SubscriptionKey key)
2170+ {
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 ())
2176+ {
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+ };
2190+
2191+ std::async (launch,
2192+ [](std::future<response::Value> document)
2193+ {
2194+ return document.get ();
2195+ }, operation->resolve (selectionSetParams, registration->selection , registration->data ->fragments , registration->data ->variables )).get ();
2196+ }
2197+
2198+ unsubscribe (key);
2199+ }
2200+
21362201void Request::deliver (const SubscriptionName& name, const std::shared_ptr<Object>& subscriptionObject) const
21372202{
21382203 deliver (std::launch::deferred, name, subscriptionObject);
0 commit comments