Bug 1512456 - P7. Chain promises so they can be exclusive. r=gerald

Differential Revision: https://phabricator.services.mozilla.com/D14031

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2018-12-11 10:54:20 +00:00
parent dc9ee1f6ee
commit b61cc66043
2 changed files with 23 additions and 21 deletions

View File

@ -48,7 +48,7 @@ void ClientSourceOpChild::DoSourceOp(Method aMethod, const Args& aArgs) {
MOZ_DIAGNOSTIC_ASSERT(promise);
// Capture 'this' is safe here because we disconnect the promise
// ActorDestroy() which ensures nethier lambda is called if the
// ActorDestroy() which ensures neither lambda is called if the
// actor is destroyed before the source operation completes.
//
// Also capture the promise to ensure it lives until we get a reaction

View File

@ -357,16 +357,17 @@ RefPtr<GenericPromise> ServiceWorkerManager::StartControllingClient(
// Always check to see if we failed to actually control the client. In
// that case removed the client from our list of controlled clients.
promise->Then(SystemGroup::EventTargetFor(TaskCategory::Other), __func__,
[](bool) {
// do nothing on success
},
[self, aClientInfo](nsresult aRv) {
// failed to control, forget about this client
self->StopControllingClient(aClientInfo);
});
return promise;
return promise->Then(
SystemGroup::EventTargetFor(TaskCategory::Other), __func__,
[](bool) {
// do nothing on success
return GenericPromise::CreateAndResolve(true, __func__);
},
[self, aClientInfo](nsresult aRv) {
// failed to control, forget about this client
self->StopControllingClient(aClientInfo);
return GenericPromise::CreateAndReject(aRv, __func__);
});
}
RefPtr<ClientHandle> clientHandle = ClientManager::CreateHandle(
@ -392,16 +393,17 @@ RefPtr<GenericPromise> ServiceWorkerManager::StartControllingClient(
// Always check to see if we failed to actually control the client. In
// that case removed the client from our list of controlled clients.
promise->Then(SystemGroup::EventTargetFor(TaskCategory::Other), __func__,
[](bool) {
// do nothing on success
},
[self, aClientInfo](nsresult aRv) {
// failed to control, forget about this client
self->StopControllingClient(aClientInfo);
});
return promise.forget();
return promise->Then(
SystemGroup::EventTargetFor(TaskCategory::Other), __func__,
[](bool) {
// do nothing on success
return GenericPromise::CreateAndResolve(true, __func__);
},
[self, aClientInfo](nsresult aRv) {
// failed to control, forget about this client
self->StopControllingClient(aClientInfo);
return GenericPromise::CreateAndReject(aRv, __func__);
});
}
void ServiceWorkerManager::StopControllingClient(