You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have code that takes a shared_ptr<bool> as a "cancel marker" for when an outer IAsyncOperation calls an inner long-running-but-non-async method, like this:
winrt::IAsyncOperation<winrt::hstring> GetStringOfManyThingsAsync() {
auto lifetime{get_strong()};
auto sharedCancel = std::make_shared<bool>(false);
auto canceltoken = co_awaitwinrt::get_cancellation_token();
canceltoken.enable_propagation(); // not _strictly_ necessary since this does not await anything else
canceltoken.callback([sharedCancel] { *sharedCancel = true; });
co_awaitwinrt::resume_background();
auto moreThings = CallOtherCodeSynchronously(..., sharedCancel);
co_returnStringFromMoreThigns(moreThings);
}
autoCallOtherCodeSynchronously(auto... std::shared_ptr<bool> cancelToken) {
for (int i = 0; i < 200 && !*cancelToken; ++i) {
DoSlowThing();
}
return ...;
}
It'd be neat if instead we could say this:
winrt::IAsyncOperation<winrt::hstring> GetStringOfManyThingsAsync() {
auto lifetime{get_strong()};
auto canceltoken = co_awaitwil::get_shared_cancellation_token();
canceltoken.enable_propagation(); // not _strictly_ necessary since this does not await anything elseco_awaitwinrt::resume_background();
auto moreThings = CallOtherCodeSynchronously(..., canceltoken);
co_returnStringFromMoreThigns(moreThings);
}
autoCallOtherCodeSynchronously(auto... std::shared_ptr<bool> cancelToken) {
for (int i = 0; i < 200 && !*cancelToken; ++i) {
DoSlowThing();
}
return ...;
}
Or maybe instead we say this:
auto canceltoken = co_awaitwinrt::get_cancellation_token();
auto sharedCanceller = wil::make_shared_cancel(canceltoken);
And then code passes around the shared_cancel_token instead of the shared_ptr. Then we could also do things like hang a wait() off of that using WaitOnAddress (expanding the size of m_canceled to be a pointer) or expose an event handle for use with WFMO.
The text was updated successfully, but these errors were encountered:
We have code that takes a
shared_ptr<bool>
as a "cancel marker" for when an outer IAsyncOperation calls an inner long-running-but-non-async method, like this:It'd be neat if instead we could say this:
Or maybe instead we say this:
... where sharedCanceller is basically this:
And then code passes around the shared_cancel_token instead of the shared_ptr. Then we could also do things like hang a
wait()
off of that using WaitOnAddress (expanding the size of m_canceled to be a pointer) or expose an event handle for use with WFMO.The text was updated successfully, but these errors were encountered: