mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 08:42:13 +00:00
Bug 1321744. Part 2 - add the ability of promise chaining to Then(). r=gerald
MozReview-Commit-ID: IaDgoWcmFRO --HG-- extra : rebase_source : 420834ba105e2606e10f2dfef480a3586a5f8fb3 extra : intermediate-source : 1c2f25bdf9e1dcac085df830e6de7193d66dbe10 extra : source : 4bb6d68fb29d3b0c5eb3a66705b69892b1c94ad4
This commit is contained in:
parent
dea1beb2c4
commit
fbfcb37762
@ -678,6 +678,28 @@ private:
|
||||
return thenValue.forget();
|
||||
}
|
||||
|
||||
// Allow RefPtr<MozPromise> p = somePromise->Then();
|
||||
// p->Then(thread1, ...);
|
||||
// p->Then(thread2, ...);
|
||||
operator RefPtr<MozPromise>()
|
||||
{
|
||||
RefPtr<ThenValueBase> thenValue = mThenValue.forget();
|
||||
// mCompletionPromise must be created before ThenInternal() to avoid race.
|
||||
RefPtr<MozPromise> p = new MozPromise::Private(
|
||||
"<completion promise>", true /* aIsCompletionPromise */);
|
||||
thenValue->mCompletionPromise = p;
|
||||
// Note ThenInternal() might nullify mCompletionPromise before return.
|
||||
// So we need to return p instead of mCompletionPromise.
|
||||
mReceiver->ThenInternal(mResponseThread, thenValue, mCallSite);
|
||||
return p;
|
||||
}
|
||||
|
||||
// Allow calling ->Then() again for more promise chaining.
|
||||
RefPtr<MozPromise> operator->()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
AbstractThread* mResponseThread;
|
||||
const char* mCallSite;
|
||||
|
Loading…
Reference in New Issue
Block a user