Merge pull request #423 from CesiumGS/unwrapped-shared-futures

Allow a continuation attached to a SharedFuture to return a Future (rather than a normal value)
This commit is contained in:
Nithin Pranesh 2022-01-24 10:28:34 -05:00 committed by GitHub
commit 0db47a52af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 3 deletions

View File

@ -33,6 +33,7 @@
##### Fixes :wrench:
- Fixes a bug where `notifyTileDoneLoading` is not called when encountering Ion responses that can't be parsed.
- Fixed a bug that prevented a continuation attached to a `SharedFuture` from returning a `Future` itself.
### v0.11.0 - 2022-01-03

View File

@ -59,7 +59,7 @@ template <typename T> struct WithTracingShared {
return result;
};
#else
return Impl::unwrapFuture<Func, T>(std::forward<Func>(f));
return Impl::unwrapSharedFuture<Func, T>(std::forward<Func>(f));
#endif
}
@ -67,7 +67,7 @@ template <typename T> struct WithTracingShared {
static auto end([[maybe_unused]] const char* tracingName, Func&& f) {
#if CESIUM_TRACING_ENABLED
return [tracingName,
f = Impl::unwrapFuture<Func, T>(std::forward<Func>(f)),
f = Impl::unwrapSharedFuture<Func, T>(std::forward<Func>(f)),
CESIUM_TRACE_LAMBDA_CAPTURE_TRACK()](const T& result) mutable {
CESIUM_TRACE_USE_CAPTURED_TRACK();
if (tracingName) {
@ -76,7 +76,7 @@ template <typename T> struct WithTracingShared {
return f(result);
};
#else
return Impl::unwrapFuture<Func, T>(std::forward<Func>(f));
return Impl::unwrapSharedFuture<Func, T>(std::forward<Func>(f));
#endif
}
};

View File

@ -12,6 +12,10 @@ struct IdentityUnwrapper {
template <typename Func> static Func unwrap(Func&& f) {
return std::forward<Func>(f);
}
template <typename Func> static Func unwrapShared(Func&& f) {
return std::forward<Func>(f);
}
};
template <typename T> struct ParameterizedTaskUnwrapper {
@ -20,6 +24,11 @@ template <typename T> struct ParameterizedTaskUnwrapper {
return f(std::move(t))._task;
};
}
template <typename Func> static auto unwrapShared(Func&& f) {
return
[f = std::forward<Func>(f)](const T& t) mutable { return f(t)._task; };
}
};
struct TaskUnwrapper {
@ -38,6 +47,16 @@ template <typename Func, typename T> auto unwrapFuture(Func&& f) {
ParameterizedTaskUnwrapper<T>>::type::unwrap(std::forward<Func>(f));
}
template <typename Func, typename T> auto unwrapSharedFuture(Func&& f) {
return std::conditional<
std::is_same<
typename ContinuationReturnType<Func, T>::type,
typename RemoveFuture<
typename ContinuationFutureType<Func, T>::type>::type>::value,
IdentityUnwrapper,
ParameterizedTaskUnwrapper<T>>::type::unwrapShared(std::forward<Func>(f));
}
template <typename Func> auto unwrapFuture(Func&& f) {
return std::conditional<
std::is_same<
@ -48,6 +67,10 @@ template <typename Func> auto unwrapFuture(Func&& f) {
TaskUnwrapper>::type::unwrap(std::forward<Func>(f));
}
template <typename Func> auto unwrapSharedFuture(Func&& f) {
return unwrapFuture(std::forward<Func>(f));
}
//! @endcond
// End omitting doxgen warnings for Impl namespace
} // namespace Impl