Commit c786c444 authored by Kenton Varda's avatar Kenton Varda

Fix `newAdaptedPromise<Promise<T>, Adapter>()`.

This was failing to chain the promises, and so returning `Promise<Promise<T>>`.

The idea here is you can create a PromiseAdapter which eventually produces another promise to chain to. The adapter is finished and should be destroyed at that point, but the final promise should then redirect to the new promise.
parent c826a71a
......@@ -1119,9 +1119,12 @@ bool PromiseFulfiller<void>::rejectIfThrows(Func&& func) {
}
template <typename T, typename Adapter, typename... Params>
Promise<T> newAdaptedPromise(Params&&... adapterConstructorParams) {
return Promise<T>(false, heap<_::AdapterPromiseNode<_::FixVoid<T>, Adapter>>(
kj::fwd<Params>(adapterConstructorParams)...));
_::ReducePromises<T> newAdaptedPromise(Params&&... adapterConstructorParams) {
Own<_::PromiseNode> intermediate(
heap<_::AdapterPromiseNode<_::FixVoid<T>, Adapter>>(
kj::fwd<Params>(adapterConstructorParams)...));
return _::ReducePromises<T>(false,
_::maybeChain(kj::mv(intermediate), implicitCast<T*>(nullptr)));
}
template <typename T>
......
......@@ -311,7 +311,7 @@ private:
friend class Promise;
friend class EventLoop;
template <typename U, typename Adapter, typename... Params>
friend Promise<U> newAdaptedPromise(Params&&... adapterConstructorParams);
friend _::ReducePromises<U> newAdaptedPromise(Params&&... adapterConstructorParams);
template <typename U>
friend PromiseFulfillerPair<U> newPromiseAndFulfiller();
template <typename>
......@@ -460,7 +460,7 @@ public:
};
template <typename T, typename Adapter, typename... Params>
Promise<T> newAdaptedPromise(Params&&... adapterConstructorParams);
_::ReducePromises<T> newAdaptedPromise(Params&&... adapterConstructorParams);
// Creates a new promise which owns an instance of `Adapter` which encapsulates the operation
// that will eventually fulfill the promise. This is primarily useful for adapting non-KJ
// asynchronous APIs to use promises.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment